Can't Compile Global Semaphores?
Jack Stouffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 27 13:56:58 PDT 2015
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();
}
More information about the Digitalmars-d-learn
mailing list