How to Best Use core.sync.rwmutex

Andrew Wiley wiley.andrew.j at gmail.com
Mon Sep 26 00:43:44 PDT 2011


ReadWriteMutex (http://www.d-programming-language.org/phobos/core_sync_rwmutex.html)
doesn't seem to play too well with the built-in monitor system. I've
been thinking about "safe" ways to use it, and the best I've come up
with is this:

shared class SomeData {
private:
ReadWriteMutex rwmutex;

...

public:
void readSomeData() {
synchronized(rwmutex.reader) {
...
}
}

void writeSomeData() {
synchronized(rwmutex.writer) {
...
}
}

}

This seems like it should work, but from TDPL, it doesn't really seem
to be what shared classes are meant for. Is there a better way to get
this sort of locking? Was ReadWriteMutex intended to be used
differently?


More information about the Digitalmars-d mailing list