uv_async_send without coalescing #4384
-
What if we don't need coalescing? And I saw #619 , it suggests we would use a thread-safe queue structure. But there is a queue in the message loop of libuv, why should we introduce another queue? Why it forces coalescing? Is there a |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
No. Libuv's design philosophy is to provide basic building blocks. If you want something like an (un)bounded channel, it's up to you to build out that abstraction. |
Beta Was this translation helpful? Give feedback.
-
I'm a little bit confused. If What does node.js do? Does node.js create its own thread-safe queue structure? |
Beta Was this translation helpful? Give feedback.
-
What would no coalescing let you do that you can't do now? Or phrased another way: what exactly are you trying to accomplish? |
Beta Was this translation helpful? Give feedback.
-
When we use Node.js, we notice that it creates a great pattern of programming. That is the single-threaded mode. This mode simplifies the structure of the production code and avoids a lot of tricky defects which are introduced by multi-threaded programming such as race condition and deadlock. When we get involved into a C++ project, I insist on the same pattern which Node.js introduces. So we choose libuv, a wonderful async framework. We expect to eliminate all of the synchronization objects such as mutex, event, etc. by means of integrating libuv. We have to use mutex again for introducing a thread-safe queue. We really want to remove all of the core objects and do Node.js ways in C++. Is it possible to provide an option to turn off coalescing? |
Beta Was this translation helpful? Give feedback.
-
Note that If you're asking for N calls = N callbacks behavior and nothing else, then I guess that could be implemented but it doesn't seem that useful because you still need to check what exactly happened and that's going to involve atomic variables or mutexes. |
Beta Was this translation helpful? Give feedback.
-
Inter-threaded communication always involves a small amount of data. In the doc, async.data = (void*) &percentage;
uv_async_send(&async); We are doing the same thing. We send the candidate (a small amount of data) together with the notification signal. We just need all of them be received. |
Beta Was this translation helpful? Give feedback.
-
OK then, we'll keep our thread-safe queue. But I think libuv could be a queue. The node.js pattern is sustained by a queue. |
Beta Was this translation helpful? Give feedback.
Note that
uv_async_send()
won't let you send data; it's not a queue of any kind, it's just a "something happened" signal. Think of it as shorthand foruv_wake_up_event_loop_from_another_thread()
.If you're asking for N calls = N callbacks behavior and nothing else, then I guess that could be implemented but it doesn't seem that useful because you still need to check what exactly happened and that's going to involve atomic variables or mutexes.