For example i have 2 threads. I want to stop server from main thread (Thread 1).
Thread 1: main program
Thread 2: TcpServer
From libuv library:
/*
* This function will stop the event loop by forcing uv_run to end
* as soon as possible, but not sooner than the next loop iteration.
* If this function was called before blocking for i/o, the loop won't
* block for i/o on this iteration.
*/
UV_EXTERN void uv_stop(uv_loop_t*);
That means, if i would call uv_stop(tcp_server_loop)
in main thread and the server loop will be blocked because of no events on the tcpserver, then the server will be still in the loop till some event appears. (it probably checks if uv_stop
was called before the loop goes to the block mode to wait for new events).
If you run uv_run with UV_RUN_DEFAULT, it will be a blocking call. However, if you use uv_stop then uv_run will immediately return. Remember that the only function in uv that is thread safe is uv_async_send, so if you want to call uv_stop on your TcpServer loop, you will have it to do from within the loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With