Hi all,
I'm writing a component where some data are read during some methods calls and written during some commands calls. As I understand the RTT documentation, methods and commands are executed in different concurrent threads. In this case, I should explicitly protect my data so that readings and writings can not happen at the same time. Was this use case foreseen by RTT's developpers? If yes, what paradigm should I use in my component to secure access to my data both in commands and in methods? If no, should I protect my data with RTT::OS::Mutex objects?
Thanks in advance, Florent Teichteil
mutex protection for data shared between methods and commands
On Mon, Nov 2, 2009 at 15:13, <florent [dot] teichteil [..] ...> wrote:
> Hi all,
>
> I'm writing a component where some data are read during some methods calls and written during some commands calls. As I understand the RTT documentation, methods and commands are executed in different concurrent threads. In this case, I should explicitly protect my data so that readings and writings can not happen at the same time. Was this use case foreseen by RTT's developpers? If yes, what paradigm should I use in my component to secure access to my data both in commands and in methods? If no, should I protect my data with RTT::OS::Mutex objects?
Yes. You need to define a Mutex object as a class member, and lock it
using MutexLock in your commands and methods. Be careful not to hold
the mutex when calling into other components. That is, just use it to
protect data read/write and not holding the lock when calling
functions.
Advanced users may opt for lock-free containers to store their data in
(like DataObjectLockFree<MyStruct> ), but they have their limitations
too.
Peter
mutex protection for data shared between methods and commands
Hi all,
I'm writing a component where some data are read during some methods calls and written during some commands calls. As I understand the RTT documentation, methods and commands are executed in different concurrent threads. In this case, I should explicitly protect my data so that readings and writings can not happen at the same time. Was this use case foreseen by RTT's developpers? If yes, what paradigm should I use in my component to secure access to my data both in commands and in methods? If no, should I protect my data with RTT::OS::Mutex objects?
Thanks in advance,
Florent Teichteil