I understand that the event loop runs on a single process (thus, on a single core) but I'd like to know what happens when I launch threads from there.
If I launch multiple threads with uv_thread_create
or uv_queue_work
, will they run on multiple cores (if available)?
I'd hope they do, because (on Unix at least) everything is based on pthreads which is able to scale to multiple cores, but I don't know.
Also, I can't write code to check for that right now because I'm on mobile. I just posted to see if any of you guys already know the answer.
Happy holidays.
Edit: I've made the test code and everything runs on a single core.
That's really up to the kernel, but in general, it will schedule each thread to a different core (if you have multiple) so you can run your code in parallel. Note however, that libuv is not thread-safe (except for uv_async_send) so if you have multiple threads executing at once, once being the event loop, it's not safe to call libuv functions from outside the loop thread.