Concurrency on Windows (spawn)

Kapps via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 18 08:23:10 PDT 2014


On Wednesday, 18 June 2014 at 15:03:55 UTC, Ali Çehreli wrote:
> On 06/18/2014 06:28 AM, Chris wrote:
>> On Wednesday, 18 June 2014 at 11:57:06 UTC, Chris wrote:
>>> Windows: in a D-DLL I'm trying to spawn a thread. However, 
>>> nothing
>>> happens
>>>
>>> auto myThread = spawn(&myFunction, thisTid);
>>> send(myThread, arg);
>>>
>>> The thread is never called. Any ideas? Thanks!
>>>
>>> PS In an old DLL it used to work, there I called it with only 
>>> one
>>> argument, i.e. spawn(&myFunction). Is thisTid messing it up, 
>>> do I need
>>> to pass something else?
>>
>> Mystery solved. There was an audio delay so that the program 
>> had already
>> finished, before the thread was properly executed. I _loooove_ 
>> Windows!
>> Not!
>
> That can happen on Linux as well. So, the owner may have to 
> call thread_joinAll() to wait for the worker:
>
> import core.thread;
>
>     auto myThread = spawn(&myFunction, thisTid);
>     send(myThread, arg);
>
>     // ... sometime before the program ends:
>     thread_joinAll();
>
> Ali

Alternatively, one should use non-daemon threads for this purpose.
http://dlang.org/phobos/core_thread.html#.Thread.isDaemon


More information about the Digitalmars-d-learn mailing list