www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to Best Use core.sync.rwmutex

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?
Sep 26 2011