Quantcast
Viewing latest article 1
Browse Latest Browse All 4

Answer by Grégory Vaumourin for Need for Mutex while using Shared Memory (C++) for hardware applications

The problem in your case is the reader can read at the same time as the variable is being written , the problem is only the write so I suggest you to use atomic operations for this write so you won't need mutex. The reads are atomics if the data is align (see Read and Write atomic operation implementation in the Linux Kernel) , I'm not sure for the write operations , but maybe they're not so let's what we can do :

In C++, the STL provide some materials to garantee that operations are atomic see : http://en.cppreference.com/w/c/atomicIn C, I found this type sig_atomic_t defined in the standard http://www.gnu.org/software/libc/manual/html_node/Atomic-Types.html that garantee atomic operations for reads and write , It should do the trick without mutex.


Viewing latest article 1
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>