Can't Compile Global Semaphores?

Matt Richardson matt at r-sonlabs.com
Mon Oct 8 15:43:30 UTC 2018


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.


More information about the Digitalmars-d-learn mailing list