On Monday, 27 July 2015 at 20:12:10 UTC, John Colvin wrote:
Yes, but then core.sync.semaphore doesn't support being shared, so...

Ok, so I made the code run by using __gshared instead of shared. It seems really odd that a semaphore object doesn't support being shared, this that a bug?

Here is the modified code:

import core.sync.semaphore;
import core.thread;
import std.string;
import std.stdio;

__gshared string data;
__gshared Semaphore sem;


void read() {
    data = "From Thread";
    sem.notify();
}


void write() {
    sem.wait();
    data.writeln;
}


void main() {
    sem = new Semaphore();
    Thread reader = new Thread(&read);
    Thread writer = new Thread(&write);

    reader.start();
    writer.start();
}

Reply via email to