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

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 13 09:35:03 PDT 2007


"Janice Caron" wrote
> - - - - you still need to be careful - - - -
>
> There is no magic bullet to thread-safety. This mechanism does ensure
> that multiple threads won't try to access the same variable at the
> same time, but what it /won't/ do is prevent deadlocks. It's also
> still possible to screw up. For instance - you cannot get a write lock
> if you already hold a lock...
>
> scope a = readable(x);
> scope b = writable(x); /* Error - b is already locked by this thread */

magic bullet time:

At least for this case, you could put debug-only code in the core 
functionality of the locking code that checks to see if the thread already 
has the object locked.  If it does, throw an exception.

This won't help in the case where two threads deadlock, but there may be 
ways to put debug code in to check those also:

if(object a is locked by thread x && thread x is waiting for object b && I 
have object b locked)
  throw new DeadlockException();

In the release version, the system runs at full speed because this overhead 
is gone.

-Steve 





More information about the Digitalmars-d mailing list