Problem about multi-thread programming

Chris Cain clcain at uncg.edu
Sat May 5 10:02:58 PDT 2012


On Saturday, 5 May 2012 at 09:28:34 UTC, Tongzhou Li wrote:
> On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote:
>> What's in console?
>
> object.Error: Access Violation
> ----------------
> ----------------
>
> Expected output:
> 12341234123....
>
> PS:
> Line 13 should be: write(Idx);

By default, everything is TLS (thread local) ... so, cv[0] will 
be null in main even though another thread set it to something 
else.

Adding __gshared in front of "Condition[4] cv;" on line 7 will 
make it not crash with the Access Violation. However, I highly 
recommend you read the concurrency chapter in the DPL book: 
http://www.informit.com/articles/article.aspx?p=1609144


More information about the Digitalmars-d-learn mailing list