Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import std.stdio: writeln, writefln;
import core.thread: Thread;
import core.sync.mutex: Mutex;
import core.atomic: atomicOp;
shared class SharedClass {
int x = 0;
Mutex mutex;
this() {
// mutex = new shared Mutex; // Error: None of the overloads of '__ctor' are
// callable using a shared object
mutex = cast(shared)new Mutex;
private void workFunction() {
// mutex.lock(); // Error: non-shared method
writefln("x was %d", x);
writefln("x is now %d", x);
// mutex.unlock(); // Error: non-shared method
void doWork() {
writeln("Starting work...");
Thread[5] threads;
foreach(i; 0..threads.length) {
// threads[i] = new Thread(&workFunction); // Error: None of the overloads
// of '__ctor' are callable
// using argument type
// (void delegate() shared)
threads[i] = new Thread(cast(void delegate())&workFunction);
void main() {
auto sharedClass = new shared SharedClass();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment