New scope modifier "unshared" for temporary ownership of shared data

Dicebot public at dicebot.lv
Wed Apr 9 05:05:11 PDT 2014


On Wednesday, 9 April 2014 at 11:36:15 UTC, Marco Leise wrote:
> Since only functions performing a single operation on a
> single shared operand can accept shared variables, it is
> practically impossible to use shared mutable data in
> generic algorithms.
>
> Assuming that with this premise user code will always use a
> mutex to secure access to shared data, developers would end up
> with many casts from shared to unshared.
> So here is UNSHARED, a new scope modifier:
>
> synchronized(mutex) unshared(this.count, this.list)
> {
>     // do something with the now unshared count and list
> }
>
> This puts the mutex and the variables protected by it in
> relation in the code and removes superfluous casts.

We don't need new qualifier for that, implementing `scope` will 
do the trick among other tricks. Locking can safely cast shared 
into scope without breaking type system. And you will need same 
safety checks for implementation of "unshared" anyway 
(prohibiting storing references)


More information about the Digitalmars-d mailing list