Reputation: 21607
For a class object, I have a need for a locking mechanism that I can use for read and write methods.
I would like to be able permit multiple readers or a single writer. The same lock would apply to all class methods (one lock per object).
At the same time I would like WRITE to have priority over READ. If a writer queues, all new readers should be blocked until the writer gets and releases the lock.
Is there some built-in functionality to implement such a lock?
Upvotes: 1
Views: 138
Reputation: 1552
You want "Thread Safety" and "read-write" locks are exactly what you are after. Look for "read-write lock" on this page of the Apple documentation: Synchronisation tools
Implementation details are here and will vary depending on what you are doing with your class - see Using Locks.
Upvotes: 1