Reputation: 1670
I am using a mutex for the critical section. I have a design constraint that, 1) If 2 reads occur in 2 different thread, then critical section should be available for both. 2) If there is a write happening, then read on other thread should be blocked 3) If there is a read happening, then write on other thread should be blocked.
I dont know to do this with Createmutex, openmutex, waitforsingleobject and releasemutex apis.
Upvotes: 3
Views: 432
Reputation: 6389
If your synchronization/critical section issue is limited to a single process and many threads, i recommend you use Critical Section Objects instead of Mutex Objects. You have a couple of examples on the pages linked from msdn. Read the linked msdn pages and if you have the basic concurrency synchronization concepts and the required Windows Api knowledge under your belt, you should be rolling in no time, if not read around. There's nothing that special about Mutexes and Critical Sections from the api standpoint.
Upvotes: 0
Reputation: 1493
Take a look at the following link to see whether this native windows api meets your requirements:
Slim Reader/Writer (SRW) Locks
Upvotes: 0
Reputation: 10880
What you are looking for is a Reader-Writer lock. There are some implementations of it on the internet, for example this one.
Upvotes: 3