Search code examples
multithreadinglibuv

libuv: uv_close and thread safety


I've seen it mentioned that "uv_close is not thread safe". I'm experienced with writing multi-threaded C/C++ code, but I'm still not sure what is being said here.

  • Does this mean that uv_close must always be called in the main thread?

  • Or, is this simply warning that uv_close must not be called in parallel to other uses of the handle (seems obvious..)?

I'm dealing with an uv_async_t handle, if that's relevant...


Solution

  • Per the discussion here:

    https://github.com/libuv/libuv/issues/709

    uv_close may not be called outside of the loop thread. In addition, it should be mentioned that no libuv functions, aside from uv_async_send, are safe to call outside of the loop thread.