Walter is right about transitive readonly - here's the alternative

Janice Caron caron800 at googlemail.com
Thu Sep 13 05:04:58 PDT 2007


On 9/13/07, Regan Heath <regan at netmail.co.nz> wrote:
> [thread1]
> scope a = readable(x);
> --context switch here--
> scope b = readable(y);
>
> [thread2]
> scope b = readable(y);
> --or context switch here--
> scope a = readable(x);

In fact, this example would not deadlock, because read locks are
non-exclusive. There is absolutely no problem with multiple threads
aquiring them simultaneously. That's the whole point of them.

But if you'd said writable, then it would have been a deadlock.

In general, you just wouldn't do

 shared A a_s;
 shared B b_s;

 scope a = writable(a_s);
 scope b = writable(b_s);

because of the possibility of deadlocks. Instead, you'd do

 struct AB
 {
     A a;
     B b;
 }

 shared AB ab_s;

 scope ab = writable(ab_s);

and then refer to ab.a and ab.b.



More information about the Digitalmars-d mailing list