[dmd-concurrency] CSP: Communicating sequential processes

Sean Kelly sean at invisibleduck.org
Wed Jan 20 07:39:10 PST 2010


On Jan 20, 2010, at 4:28 AM, Michel Fortin wrote:
> 
> I'd like to note that even upgrading the lock to a write lock might be a problem: as I said in my other message, making this an automatic upgrade might force the release the reader lock until the writer lock is acquired, which would be unexpected from test()'s point of view.

ReadWriteMutex is implemented internally using a mutex and condition variable, so the basic process would be:

Upgrade:

* set thread-local heldReadLock flag
* decrement numReaders
* enter write queue

When exiting a write lock, if heldReadLock is set then it's cleared and the thread enters the read queue.  Both operations would be atomic.  But even the write lock isn't recursive so I'm hesitant to encourage people to get terribly fancy with using the lock.


More information about the dmd-concurrency mailing list