Hi,

I am currently working through a book on the fundamentals of computer concurrency and I wanted to do all of the exercises in D. But I ran into a problem when I tried to have a global semaphore:

/usr/local/Cellar/dmd/2.067.1/include/d2/core/sync/semaphore.di(35): Error: 
constructor core.sync.semaphore.Semaphore.this core.sync.semaphore.Semaphore 
cannot be constructed at compile time, because the constructor has no available 
source code

Here is my code:

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

shared string data;
shared Semaphore sem = new Semaphore();


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


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


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

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

Reply via email to