libuv 线程池的调度

原文:http://docs.libuv.org/en/latest/threadpool.html

libuv提供的threadpool可以用来在循环线程中运行用户代码和得到通知。这个内部线程池是用来运行所有的文件系统操作,以及getaddrinfo getnameinfo请求。默认大小是4,但它在启动时可以改变UV_THREADPOOL_SIZE环境变量来设置为任何值(最大是128)。threadpool是全局的,为所有事件循环共享当一个特定的函数利用threadpool(即使用uv_queue_work())时,libuv预分配和初始化UV_THREADPOOL_SIZE所允许的最大线程数。这将导致一个相对较小的内存开销:128个线程~ 1 mb,但增加了线程在运行时的性能。

注意:所有事件循环共享一个全局的线程池,但这些函数(libuv的线程池API)并不是线程安全的。

Data types

uv_work_t

Work request type.

void  (*uv_work_cb) ( uv_work_t*  req )

Callback passed to uv_queue_work() which will be run on the thread pool.

void  (*uv_after_work_cb) ( uv_work_t*  req, int  status )

Callback passed to uv_queue_work() which will be called on the loop thread after the work on the threadpool has been completed. If the work was cancelled using uv_cancel() status will be UV_ECANCELED.

Public members

uv_loop_tuv_work_t.loop

Loop that started this request and where completion will be reported. Readonly.

See also

 

The uv_req_t members also apply.

API

int  uv_queue_work ( uv_loop_t*  loopuv_work_t*  requv_work_cb  work_cbuv_after_work_cb  after_work_cb )

Initializes a work request which will run the given work_cb in a thread from the threadpool. Once work_cb is completed,after_work_cb will be called on the loop thread.

This request can be cancelled with uv_cancel().


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值