boost thread tutorial

几篇关于boost thread的文章。
1  The Boost Thread Library(http://www.ddj.com/cpp/184401518?pgno=1)
    给出了几个例子示范了线程的各项常见操作,如创建,中断,共享等。由Bill Kempf在2002年写的。
2 What's new in Boost Threads?(http://www.ddj.com/cpp/211600441?pgno=3)
   介绍了Boost1.35的几个新变换。由Antony Williams写于2008年
1) thread对象可以做右值
boost::thread create_thread()
{
void some_function();
boost::thread t(some_function);
return boost::move(t);
}
boost::thread threads[45];
threads[12]=boost::move(create_thread());
注意create_thread函数的返回值是个thread对象,return语句返回了一个thread对象。而且thread对象还可以存到thread对象数组。

2) 创建thread对象时,可以像这样给线程将要运行的函数传参数:
void thread_func   (int i,double d,std::string s);
boost::thread t(thread_func, 42,3.141,"hello world");
 这样的写法感觉很自然
3)线程对象的确定,线程对象现在含有一个ID对象,标志了其身份,所以可以通过这个这个ID来进行比较两个线程的身份。

Thread  IDs sport the full range of comparison operators, and can be freely copied. If two thread IDs represent the same thread they compare equal, and if they represent different threads then they are not equal. Also, the thread IDs for distinct threads form a total order, so they can be used as keys in associative containers such as std::map<>.

这句话说Thread IDS支持各种比较操作。另外由于不重复,可以放在map里。不会冲突哦。

3 令一篇boost文章,介绍了boost.thread类里的各方法,属性
http://www.boost.org/doc/libs/1_37_0/doc/html/thread.html
也是Antony Williams写的,介绍的是Boost 1.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值