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

Marco Leise Marco.Leise at gmx.de
Wed Apr 9 04:39:31 PDT 2014


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.

-- 
Marco



More information about the Digitalmars-d mailing list