Lock Options in D article in Dr. Dobb's
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat Dec 13 03:31:52 PST 2008
Walter Bright wrote:
> Bartosz Milewski has just published "Lock Options" in the January Dr.
> Dobb's.
>
> http://www.ddj.com/cpp/212201754
>
> He provides a D implementation of it.
Unfortunately, I'm pretty sure it's buggy :(.
In his final implementation he uses a mixin to create a declaration for
a scope variable (the lock).
That variable will be destroyed before the end of the mixin, not before
the end of the containing scope (statement mixins create an implicit scope).
See for yourself:
-----
module test;
import tango.io.Console;
class Verbose {
this() { Cout("Constructed").newline(); }
~this() { Cout("Destructed").newline(); }
}
void main() {
Cout("Start of main").newline();
mixin("scope lock = new Verbose;");
Cout("End of main").newline();
}
-----
Output:
=====
Start of main
Constructed
Destructed
End of main
=====
It should work without that mixin, but it won't be nearly as nice-looking.
More information about the Digitalmars-d-announce
mailing list