On 09/15/2015 04:49 PM, BBasile wrote:
Under Windows this works fine but under Linux I got a runtime error.
Can it be because 'param' is invalid at the time clbck is called? The following program works under Linux. However, removing thread_joinAll() is a bug:
import std.parallelism; import std.stdio; alias CallBack = void function(void*); class Foo { CallBack clbck; void* param; void dotask() { // some heavy processing // tells the caller that some fresh data are available if(clbck) clbck(param); // debugger breaks HERE } void call() { task(&dotask).executeInNewThread; // returns directly but the caller will get a notif when finished } } void handler(void* p) { writefln("Finishing with %s at %s", *(cast(int*)p), p); } void main() { auto foo = new Foo(); foo.clbck = &handler; int i = 42; foo.param = &i; foo.call(); import core.thread; thread_joinAll(); } Ali