Is it safe to run uv_run(uv_default_loop()) from a different thread at different time? #4728
Replies: 3 comments 5 replies
-
|
You should only use the loop from one thread at a time. That is, if your app can gaurantee the loop is only running and loop APIs are only being called from one thread at a time, you will be fine. Note that libuv won't prevent you from using it from multiple threads at the same time, but the results of that cill be catastrophic. |
Beta Was this translation helpful? Give feedback.
-
|
Note that in the default libuv configuration, the windows kernel will "protect" you and only run one of those threads at a time afterwards which can lead to scaling problems unless you patch libuv (as does electron, JuliaLang) to disable this kernel "feature" |
Beta Was this translation helpful? Give feedback.
-
|
I think the electron related modifications are here? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This question has been asked many times before, but I still want to ask it and consider whether there is a better paradigm.
I want to have the main thread wait for TCP connection and do some operations, and once the operations is done, all TCP read and write operations will be offloaded to a new thread for execution. Therefore, I will use uv_run() at different times: for the main thread, it is
uv_run(uv_default_loop(), UV_RUN_ONCE), and for the new thread, it isuv_run(loop, UV_RUN_DEFAULT).A brief pseudo-code example would be as follows:
Is this approach safe? Or is there a better paradigm? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions