You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is going to require some careful design work. Just thinking through how I would call 2 JS imports that share some JS state it seems like we will need some careful coordination - either transparent to the user (how?)
It seems like we want to focus on a couple of key scenarios to help us hone in on a good design.
For example:
"make fetch and C# HttpClient.GetAsync usable from any thread
"make it possible to load a JS library into a Web Worker and usable from a single (non-threadpool) Thread"
"make it possible to link the result of a JS call to a particular thread and make it possible to return to that thread for subsequent operations"
Some open questions:
what should happen if a worker is reused for a new thread? Shoudl the JS libraries that were loaded before be unloaded somehow?
What to do with JS libraries that expose "void void" functions that don't take any arguments or results but that need to be tied to a particular threads?
Should we allow returning to the same threadpool thread? how - by installing a SynchronizationContext transparently? require the user to set things up explicitly?
@imoldfella what do you mean by "initial webworker"? Right now our deployment model is to run the .NET main thread on the main browser thread. So if you navigate away from a page, for example, the main thread (and with it, all the underlying Emscripten infrastructure) will be gone. Any webworkers will be terminated (as you linked above), but even if they weren't they will probably fail ungracefully since so much of the Emscripten threading support relies on being able to communicate with the main browser thread.
ah, thanks for pointing that out. Normally having webassembly in a worker is convenient because without threads it's difficult to cancel things other than with terminate, but what you described makes perfect sense. Should I be able to use a CancellationToken if I need to stop a task running on a worker thread?
Activity
lambdageek commentedon Oct 20, 2022
I think this is going to require some careful design work. Just thinking through how I would call 2 JS imports that share some JS state it seems like we will need some careful coordination - either transparent to the user (how?)
Ie suppose I exposed a JS dictionary:
how would I guarantee that
AddPropertyandLookupPropertyare called from the same thread?What if I'm in an async method?
What if I'm in a threadpool thread?
lambdageek commentedon Oct 20, 2022
It seems like we want to focus on a couple of key scenarios to help us hone in on a good design.
For example:
fetchand C#HttpClient.GetAsyncusable from any threadSome open questions:
imoldfella commentedon Nov 30, 2022
Maybe one more question - what happens when initial webworker is terminated? are the workers being used for multithreading terminated immediately, or eventually, or never? https://html.spec.whatwg.org/multipage/workers.html#dom-worker-terminate-dev
lambdageek commentedon Dec 1, 2022
@imoldfella what do you mean by "initial webworker"? Right now our deployment model is to run the .NET main thread on the main browser thread. So if you navigate away from a page, for example, the main thread (and with it, all the underlying Emscripten infrastructure) will be gone. Any webworkers will be terminated (as you linked above), but even if they weren't they will probably fail ungracefully since so much of the Emscripten threading support relies on being able to communicate with the main browser thread.
imoldfella commentedon Dec 1, 2022
ah, thanks for pointing that out. Normally having webassembly in a worker is convenient because without threads it's difficult to cancel things other than with terminate, but what you described makes perfect sense. Should I be able to use a CancellationToken if I need to stop a task running on a worker thread?