I'm looking to do something like this now, but I can't see where I should 
start my search. I found that EM_ASM is a define of an other fonction 
insite of `emscripten.h` but I don't know where I have to look to start to 
implement an `EM_ASM_MAIN_THREAD` macro.

Le dimanche 24 avril 2016 04:08:38 UTC-4, jj a écrit :
>
> Something that I've been thinking about is if we did a 
> EM_ASM_MAIN_THREAD(...) macro that would be identical to EM_ASM, except 
> that when a pthread executes it, it would proxy the EM_ASM call to the main 
> thread to execute, and then pause to wait for the main thread to report 
> back. This might allow these kind of EM_ASM_MAIN_THREAD(alert('message')); 
> situations at least, where performance is not a concern (e.g. debugging, 
> startup, critical failures, ..). This could also work in a limited fashion 
> in non-pthreads builds when --proxy-to-worker is used.
>
> As a sidenote, console.log() and console.error() are already posted from 
> pthreads to the main thread, so those can be freely used in EM_ASM blocks 
> in pthreads and should work.
>
> 2016-04-22 20:45 GMT+03:00 Alon Zakai <[email protected] <javascript:>>:
>
>> If I understand the question, it sounds like you want to write a method 
>> in JavaScript in your HTML, and have it be executed when a worker is 
>> created? Do you want it to run in the HTML (on the main thread) or in the 
>> worker?
>>
>> If in HTML, then you can modify the code that creates workers (not sure 
>> where, but looking for new Worker() in src/ should find it). Or, you might 
>> just patch Worker itself in the main scope, replace it with another method 
>> that wraps around it. Overall I don't think we have a nice way to do that 
>> right now.
>>
>> If in the worker, then you can't directly do that - functions can't be 
>> passed from workers, only JSON-type data.
>>
>> On Thu, Apr 21, 2016 at 7:55 AM, Kerby Geffrard <[email protected] 
>> <javascript:>> wrote:
>>
>>> Hi,
>>>
>>> I was wondering if there's a way to attach any function to any worker 
>>> that Emscripten create. I want to do that because I want to add an event 
>>> listener to all of my threads.
>>>
>>> What I would like to do:
>>>
>>>
>>>    - I want to be able to add a function in my shell.html (Let's call 
>>>    it *onNewWorker*)
>>>    - And when emscripten create a Worker because of a pthread in my 
>>>    project, *onNewWorker *is called with my worker passed in argument
>>>    - So since inside of my *onNewWorker *function, I can add event 
>>>    listener with my worker, all my pthread have the event listener that I 
>>> want
>>>    
>>>
>>> I want to do this because I need to add an event listener for when my 
>>> C++ thread send message with EM_ASM*. This is needed because I want to send 
>>> a message from my thread to the main thread that trigger an 
>>> `alert('message')` since we can't use alert() from workers.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "emscripten-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected] 
>>> <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to