Reputation: 72655
I have several modifying threads and some reading threads, which all access the global variable X. I want to make my synchronization policy like this:
When a thread try to modify X, it will require a lock first, and several modifying threads can have several locks required.
When a thread try to read X, it must wait until all the modifying threads drop their locks.
Is there any solution to this situation in linux pthread library? Many thanks
Upvotes: 0
Views: 187
Reputation: 45117
You are looking for a read/write lock (or reader-writer lock). I believe there is one in pthreads (pthread_rwlock_*).
Upvotes: 2