help icon indicating copy to clipboard operation
help copied to clipboard

What conditions will cause the loop to wake up from `uv_async_send`?

Open morrisonlevi opened this issue 5 years ago • 1 comments

I have a multi-threaded application, where one thread runs an event loop. If another thread calls uv_async_send, under what conditions will event loop thread wake up and trigger the callback?

Asking because I will need to block until the callback has actually executed, and need to know what sort of guarantees there are on what will wake it up. I could not find any guarantees in the docs.

morrisonlevi avatar Apr 05 '21 20:04 morrisonlevi

"Needs to block" is kind of ambiguous but I take it to mean the waker thread blocks until it gets an answer from the event loop thread?

The short answer is "always", provided you call uv_run(), your code returns control to the event loop (i.e., no busy loops), and you keep the uv_async_t handle open.

bnoordhuis avatar Apr 06 '21 06:04 bnoordhuis