Large (>32 byte) concurrency messages

JR zorael at gmail.com
Fri Aug 9 03:17:16 PDT 2013


On Thursday, 8 August 2013 at 21:16:36 UTC, David Nadlinger wrote:
> On Thursday, 8 August 2013 at 20:08:11 UTC, JR wrote:
>> I put together http://dpaste.dzfl.pl/d7322971 earlier to 
>> demonstrate some of these errors, though I didn't mention the 
>> raciness of passing pointers there. To test that race I used 
>> http://dpaste.dzfl.pl/e6fd4569.
>
> That's just a bug in your code; when taking a pointer to stack 
> data (which is un- at safe), you have to take care not to escape 
> it from the scope.

Can I manually store it on the heap and let the garbage collector 
keep it safe? I know of the opposite -- instantiating a class on 
the stack with the scope keyword -- but that doesn't help me here.

I guess I could have the sender wait for an 'okay done' priority 
message from the receiving thread before escaping the scope, but 
I don't have any guarantees that some other thread doesn't send a 
different message in the meantime (such as the server reader 
passing on a new raw string) when I'm not ready for such.

Also I could *technically* have a __gshared struct/class act as a 
container for an array of these event structs (with synchronized 
rotating push and front properties), but my pride would take a 
huge blow and I don't have enough ice cream.


More information about the Digitalmars-d-learn mailing list