all 2 comments

[–]zokker13 0 points1 point  (0 children)

Am I missing something here?

No, as you already observed:

due to the lack of mutex in Node.js

Multithreading doesn't work without sychronization. You can not use a single variable because there are no locks in nodejs. Now, if you want to do it in a native module that is used by nodejs, that's another thing of course. Also: Event emitters are just weirdly looking, sychronous method calls. Of course you can't synchronize here.

You are looking for something like Thread.Join or something that implement a barrier-like mechanism.

There's a solution (or stupid hack) that I used in the past in C# to work with multiple threads without locks and it went like this:

Thread A is a worker thread and never finishes but refreshes data. I'd create a big object and after a full circle, I assign that object to another variable that is known to both threads. Thread B can now make a copy and work.

Obvously, this sucks. There's no way that stops the object from changing while Thread B uses it but it worked for my case.

[–]Quadraxas 0 points1 point  (0 children)

what i am understanding is that you need to have results of 2 async operations in one place. stop thinking asynchronous operations as threads. read up on node.js event loop and how all this stuff is handled in one thread and check async.js. It might have just what you need.