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

Janice Caron caron800 at googlemail.com
Thu Sep 13 10:00:50 PDT 2007


On 9/13/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> > 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.

That's feasible, but non-trivial. Under the hood, there would have to
have a variable for the thread ID. The runtime cost would be an extra
atomic compare-and-set operation.

But worse, either the thread ID variable would be unused in release
mode, wasting space, or it would be absent in release mode, making the
ABI different, and hence making release and debug object files
mutually unlinkable. Tough choice!



More information about the Digitalmars-d mailing list