core.sync.rwmutex example

TheFlyingFiddle via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 10 18:28:20 PDT 2014


On Friday, 9 May 2014 at 23:12:44 UTC, Charles Hixson via 
Digitalmars-d-learn wrote:

> But I'm worried about the receiving end.  It needs, somehow, to 
> ensure that the message it receives is the appropriate message, 
> and that other messages don't get dropped while it's waiting 
> for the answer...or, perhaps worse, substituted for the 
> expected answer.  If I can depend on msg[0] of "auto msg = 
> receiveOnly!(Tid, bool)" that will allow me to check that the 
> message was received from the proper source

If you are worried that other messages having the same signature 
will be sent from other sources than the expected source you 
could make use of message tagging. Simply wrap the boolean result 
in a struct with a descriptive name.

struct SharedHashMapSetCB { bool flag; }
void set (string s, uint64_t id)
{
    tbl[s] = id;
    send (SharedHashMapSetCB(true));
}

//On the receiving end
auto msg = receiveOnly!SharedHashMapSetCB();

> But doesn't this design lock the entire hash-table while the 
> update is in progress?  Is there a better way?
I think a shared memory hash-map is better for your use case. 
Working with message passing is preferable done asynchronously. 
Blocking calls (send followed by receive) is likely to be slower 
then simply waiting on a semaphore.










More information about the Digitalmars-d-learn mailing list