Reliable CRITCAL_SECTION for shared memory?

We have some data structures that we share on Windows. (Through a shared data segment in a DLL that is loaded by all of these processes.)

We need to synchronize some calls, and we measured that the performance hit when using Mutex Win32 is too expensive.

CRITICAL_SECTION cannot be placed in shared memory due to some of its advanced features.

This leaves us with the requirement of a simple lock / mutex solution based directly on the Win32 Interlocked* family of functions.

Before rolling on my own, I would like to see if there are reliable implementations that cope with the requirement of being lightweight, fast and working in shared memory for several processes, but it seems like this is what Google is hard to do for me. (And, in any case, CodeProject hits, but it is often difficult to say whether it is a code toy or "reliable."

So I would probably need to name a recursive user-mode mutex that works for several processes when placed in shared memory on Windows (note that only part of the lock should be handled with great confidence, I can live with restrictions / additional requirements for initialization).

+6
source share
1 answer

Shared memory is a popular topic nowadays,

Try boost :: InterProcess - which provides mechanisms that can be used and uses a common X-platform code.

http://www.boost.org/doc/libs/1_52_0/doc/html/interprocess/sharedmemorybetweenprocesses.html

Another reason is that the library provides synchronization mechanisms and other IPC mechanisms that may be useful in the future.

http://www.boost.org/doc/libs/1_52_0/doc/html/interprocess/synchronization_mechanisms.html

For reference, a thing uses Atomic OPs also for a mutex:

http://www.boost.org/doc/libs/1_52_0/boost/interprocess/sync/spin/mutex.hpp

 inline void spin_mutex::lock(void) { do{ boost::uint32_t prev_s = ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0); if (m_s == 1 && prev_s == 0){ break; } // relinquish current timeslice ipcdetail::thread_yield(); }while (true); } 

Also from the "chat below" in this post, see the top answer for: Is there a difference between the Boost cloud mutex and the critical WinAPi partition?

+1
source

All Articles