Chinaunix首页 | 论坛 | 博客
  • 博客访问: 563442
  • 博文数量: 104
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1559
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-21 00:58
个人简介

锻炼精神,首先要锻炼肉体

文章分类

全部博文(104)

文章存档

2018年(1)

2016年(1)

2015年(101)

2014年(1)

我的朋友

分类: C/C++

2015-06-15 00:11:29

Threads and Boost.Asio -1.58.0

Thread Safety
线程的安全性

In general, it is safe to make concurrent use of distinct objects, but unsafe to make concurrent use of a single object.
一般来说,并发编程中的并发实体(并行运行的线程或是进程)访问各自(私有)的资源对象是安全的,但是(多个并发实体)并发的访问同一个(共享资源)对象这种情况是存在安全隐患的.

However, types such as io_service provide a stronger guarantee that it is safe to use a single object concurrently.
然而,(Boost.Asio 中所提供的)像是 io_service 这种类型(的变量)确保着并发实体并行访问同一个(共享)对象的绝对安全性


Thread Pools
线程池

Multiple threads may call io_service::run() to set up a pool of threads from which completion handlers may be invoked.
多个线程实体可通过调用 io_service::run() 这个方法来创建可容纳多个线程实体的线程池,完成句柄程序从这个线程池中选取(已经创建好的)线程实体,并通过该线程实体(作为程序载体)来运行句柄程序.

This approach may also be used with io_serivce::post() to use a means to perform any computational tasks across a thread pool.
上述的(多个线程实例创建线程池)方法也可以通过调用 io_service::post 方法来实现,通过调用 io_service::post() 这个方法创建可被任意计算任务对象访问的线程池.

Note that all threads that have joined an io_service's pool are considered equivalent ,and the io_service may distribute work across them in an arbitrary fasion.
谨记一点: 所有加入到 io_service 线程池中的线程实体(的地位)都是平等的(/也就是不存在领导者<给服从者分配任务>和服从者) ,且 io_service 对象以随机分配的方式将任务派发给线程池中的每个线程实体(执行)



阅读(1295) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

夏目玲子2015-06-17 22:56:22

一直都没更新,这个文档目前还不完整,sorry