Runtime error when calling a callback in a parallel Task
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Sep 16 15:30:26 PDT 2015
On 09/16/2015 02:01 PM, BBasile wrote:
> On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli wrote:
>> 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?
>
> No the callback and its user parameter are set at the same time.
I don't want to sound like insisting on my idea but I was more concerned
about the time when param's life ended. The callback is just a function
pointer. Functions never die, so there is no concern with that. However,
the actual variable that 'param' is pointing at may have been gone
before the callback is executed.
>> The following program works under Linux. However, removing
>> thread_joinAll() is a bug:
>
> I got to try `thread_joinAll`.
>
> The main thread is not a D program so i cant call `thread_joinAll` that
> simply. Maybe as an additonal dll export but in this case if
> `thread_joinAll` does something with the Runtime (?) it's quite probable
> that it won't have an effect. :/
In my code, thread_joinAll() simply made main() wait until the thread
finished. Otherwise, if main() ended before the thread, the int data
would be invalid when the callback was using a pointer to its (old)
location.
Ali
More information about the Digitalmars-d-learn
mailing list