libuv的多线程问题
原文:http://stackoverflow.com/questions/13838972/is-libuv-thread-safe?answertab=votes#tab-top
?
I have created a new thread dedicated to a libuv run loop. The thread function looks something like this:
uv_async_send(&exit_handle);
?
You need to take care to not call?uv_async_send()
?before the other thread has finished setting up the loop and the uv_async handle. Recent version of libuv include the?uv_barrier?synchronization primitives that you could use; but the libuv version that ships with Node.js 0.8 doesn't support this yet, so you probably need to use pthread facilities to make this work.
On a side note, you seem to be calling?uv_ref
?and?uv_unref
?with a loop reference as the argument. In recent versions of libuv this has changed, you are now supposed to?uv_ref
?and?uv_unref
?a specific handle. See?uv.h?for details.