libuv之async使用

libuv中async的使用比较难理解一些,我们来一起学习下

简介

vu_async_t是我们要用的handle,这个handle用来在线程间通信的。我们看一下官方的解释
/*
 * uv_async_t is a subclass of uv_handle_t.
 *
 * uv_async_send wakes up the event loop and calls the async handle's callback.
 * There is no guarantee that every uv_async_send call leads to exactly one
 * invocation of the callback; the only guarantee is that the callback function
 * is called at least once after the call to async_send. Unlike all other
 * libuv functions, uv_async_send can be called from another thread.
 */

也就是说配合 uv_async_send,可以唤醒持有async的消息队列,并调用async的回调,而且这个是跨线程的,只保证uv_async_send调用一次之后, callback也必然至少调用一次,但是因为是很多线程可以同时发送唤醒消息,所以,也可能被多次调用啦。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值