Skip to content

Instantly share code, notes, and snippets.

@ttldtor
Created February 2, 2015 21:41
Show Gist options
  • Save ttldtor/325b0697d524a8b68e63 to your computer and use it in GitHub Desktop.
Save ttldtor/325b0697d524a8b68e63 to your computer and use it in GitHub Desktop.
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