例如我有2 个线程。我想从主线程(线程 1)停止服务器。
线程1:主程序
线程 2:TcpServer
来自 libuv 库:
/*
* 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*);
这意味着,如果我uv_stop(tcp_server_loop)
在主线程中调用并且服务器循环将因为 tcpserver 上没有事件而被阻塞,那么服务器将仍然在循环中,直到某个事件出现。uv_stop
(它可能会在循环进入块模式以等待新事件之前检查是否被调用)。