The following code does core dump (compiled with gdc). Pointers will be appreciated.
import std.stdio;
import std.conv;
import std.math;
import std.concurrency;
import core.thread;
import core.sync.mutex;

enum count = 5;
__gshared double rslt = 0.0;
__gshared Mutex mutex;

void term(immutable(int)* nterm) {
        double r;
        auto n = to!double(*nterm);
        r = 4.0*pow(-1.0, *nterm)/(2.0*n + 1);
        writefln("%s: %6.6f.", *nterm, r);
        mutex.lock();
           rslt = rslt + r;
        mutex.unlock();
}


void main() {

    foreach (i; 0 .. count) {
        int* jm = new int;
        *jm = i;
        immutable int *j = cast(immutable) jm;
        Tid tid = spawn(&term, j);
    }

    thread_joinAll();
    writefln("Result: %6.9f.", rslt);
}

-ish

Reply via email to