Something needs to happen with shared, and soon.
Jason House
jason.james.house at gmail.com
Wed Nov 14 17:30:30 PST 2012
On Monday, 12 November 2012 at 02:31:05 UTC, Walter Bright wrote:
>
> To make a shared type work in an algorithm, you have to:
>
> 1. ensure single threaded access by aquiring a mutex
> 2. cast away shared
> 3. operate on the data
> 4. cast back to shared
> 5. release the mutex
This is a fairly reasonable use of shared, but it is bypassing
the type system. Once shared is cast away, it is free to be mixed
with thread local variables. Pieces can be assigned to non-shared
globals, impure functions can stash reference, weakly pure
functions can mix their arguments together, etc... If locking
converts shared(T) to bikeshed(T), I bet some of safeD's logic
for no escaping references could be used to improve things.
It's also interesting to note that casting away shared after
taking a lock implicitly means that everything was transitively
owned by that lock. I wonder how well a library could
promote/enforce such a thing?
More information about the Digitalmars-d
mailing list