Created
February 2, 2015 21:41
-
-
Save ttldtor/325b0697d524a8b68e63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import core.thread; | |
class A { | |
void opCall(int i) const shared { | |
write(i); | |
} | |
}; | |
shared(const A) foo() { | |
static shared A a = new A(); | |
return a; | |
} | |
void w() { | |
for(int i = 0; i < 1000; ++i) { | |
foo()(1); | |
} | |
} | |
void w2() { | |
for(int i = 0; i < 1000; ++i) { | |
foo()(2); | |
} | |
} | |
void main() { | |
auto t1 = new Thread(&w); | |
auto t2 = new Thread(&w2); | |
t1.start(); | |
t2.start(); | |
t1.join(); | |
t2.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment