I have created a new thread dedicated to a libuv run loop. The thread function looks something like this:
void thread_function()
{
uv_loop_t *loop = uv_loop_new();
uv_ref( loop );
uv_run( loop );
}
The ref counter increment keeps the thread alive and in a state to process libuv events. I hope to be able to cause the run loop to end, thus causing the thread to exit, by executing uv_unref
on the main thread.
However, on inspecting the uv_ref
source code I failed to see any guarantee that access to the reference counter variable would be synchronized during concurrent access. Additionally I did not see any yield calls to relinquish control to the operating system during the run loop, meaning the program will not cooperate well with other processes.
This leads me to believe that I am not using libuv in the right way. If someone could explain what I'm doing wrong, that would be great!