core.sync.rwmutex example

Charles Hixson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 9 10:11:59 PDT 2014


The example code from core.sync.rwmutex seems bugged.  After copying it 
I added an import for core.sync.rwmutex, and moved the executions of 
runTest into...well:
void main()
{    runTest(ReadWriteMutex.Policy.PREFER_READERS);
     runTest(ReadWriteMutex.Policy.PREFER_WRITERS);
}

Then I tried to compile it.  I got the following error messages:
test3.d(36): Error: class core.sync.rwmutex.ReadWriteMutex member 
m_commonMutex is not accessible
test3.d(38): Error: class core.sync.rwmutex.ReadWriteMutex member 
m_numQueuedReaders is not accessible
test3.d(39): Error: class core.sync.rwmutex.ReadWriteMutex member 
m_numQueuedWriters is not accessible

Checking out the documentation, I don't see that they SHOULD be 
accessible, so I think the compiler's correct, and the example is wrong.

P.S.:  Does anyone have a good working example of rwmutex?  I'm trying 
to build a hash table that is write accessible from one thread, and 
readable from anywhere, and this looked like the best way to do 
it...except that when I start to figure out how to use it I get errors.

Also does anyone have any examples of two directional communication 
between two particular threads (a bit more than just yes/no) in the 
presence of multiple other threads, so that when a thread asks another 
for information, only that other thread  is allowed to reply?  Perhaps 
that's a better way to implement the shared-read hash table.  (I'd like 
to use std.concurrency, but I can't figure out how one is supposed to 
manage specific inter-thread communications.)

-- 
Charles Hixson



More information about the Digitalmars-d-learn mailing list