WebReflection / coincident

An Atomics based Proxy to simplify, and synchronize, Worker related tasks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help preventing Harakiri

WebReflection opened this issue Β· comments

Related: pyscript/polyscript#14 (comment)

Issue

The proxy trap that cross boundaries could lead to deadlock situations without warnings whatsoever: it's basically unintended Seppuku.

// main thread
proxy.main = async () => {
  console.log(1);
  await proxy.worker();
  console.log(2);
};

// worker thread
proxy.worker = () => {
  console.log('πŸ”₯ this is fine πŸ”₯');
  // nope, not at all, this can't happen ever
  // while main() is executing
};

// here the πŸ’€πŸ”’
proxy.main();

In details

  • a worker invoking a main utility waits for completion and pauses the worker until that
  • a main invoking a worker utility while executing an exported utility can't unblock the worker that is waiting for the main to complete its task

Brainstorming

  • the worker sync-like ability is one of the best features this whole project offers ... as the code is non-blocking, yet stuck, at any specific line, it's not possible to temporarily unlock it via Atomics as the result of the main is still unknown
  • there is no way to know ahead of time if the proxy.thing is a method that exists or not, until the worker is reached
  • there is, however, the possibility to internally flag a sync execution of a main function and somehow disable, or better throw errors, if the worker utility within the main invoke is awaited while executing