www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Shared Hell

reply Kagamin <spam here.lot> writes:
Walter Bright Wrote:

 A function that accesses shared data has to put in fences. There's no 
 way to have the same code deal with shared and unshared code.

Shared code perfectly deals with unshared data (it's not guaranteed that shared data is accessed by more than one thread). In other words unshared data is implicitly castable to shared.
Oct 29 2009
next sibling parent Kagamin <spam here.lot> writes:
Kagamin Wrote:

 Walter Bright Wrote:
 
 A function that accesses shared data has to put in fences. There's no 
 way to have the same code deal with shared and unshared code.

Shared code perfectly deals with unshared data (it's not guaranteed that shared data is accessed by more than one thread). In other words unshared data is implicitly castable to shared.

Uh... this post was a little fast, ignore it, please.
Oct 29 2009
prev sibling parent Walter Bright <newshound1 digitalmars.com> writes:
Kagamin wrote:
 Walter Bright Wrote:
 A function that accesses shared data has to put in fences. There's
 no way to have the same code deal with shared and unshared code.

Shared code perfectly deals with unshared data (it's not guaranteed that shared data is accessed by more than one thread). In other words unshared data is implicitly castable to shared.

Unfortunately, there is a subtle problem with that that makes such implicit casts unsafe. Shared data can be handed off to other threads. So if thread local data is implicitly cast to shared, then it can be handed off to other threads. Meaning it is no longer guaranteed to be thread local.
Oct 29 2009