On 09/10/2018 4:43 AM, Matt Richardson wrote:
On Monday, 27 July 2015 at 20:57:00 UTC, Jack Stouffer wrote:
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();
}
I JUST found this after several hours of searching. Thank you, Jack.
Now if sharing a semaphore could be thing, I'd be happy. It's honestly
one of (it's actually a long list) the major blocks to us using D
primarily.
shared doesn't do much, so if __gshared works, use it (that is what it
is there for). So it isn't a blocker.