几篇关于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对象可以做右值
2) 创建thread对象时,可以像这样给线程将要运行的函数传参数:
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
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()注意create_thread函数的返回值是个thread对象,return语句返回了一个thread对象。而且thread对象还可以存到thread对象数组。
{
void some_function();
boost::thread t(some_function);
return boost::move(t);
}
boost::thread threads[45];
threads[12]=boost::move(create_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