http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html

launching threads
boost::thread类代表一个可执行的线程(thread of execution)。
A new thread is launched by passing an object of a callable type that can be invoked with no parameters to the constructor.
The object is then copied into internal storage, and invoked on the newly-created thread of execution.
If you wish to construct an instance of boost::thread with a function or callable object that requires arguments to be supplied, this can be done using boost::bind.
(thread non-copiable, but movable; object that used to created a thread must callable, if not, use boost::ref)

Joining and detaching
当代表一个可执行的线程(thread of execution)的boost::thread对象被销毁时,这个线程便同时被detached. Detached的线程将继续运行直到线程终止。
也可以显式调用(explicitly)一个boost::thread对象的detach()方法,这时这个线程直接被detach,而这个boost::thread对象讲不再代表thread of execution,而指Not-a-Thread

join()用于等待一个线程结束。
(timed_join())

Interruption
调用boost::thread对象的interrupt()方法,可以中断其对应的线程。
When the interrupted thread next executes one of the specified interruption points (or if it is currently blocked whilst executing one) with interruption enabled, then a boost::thread_interrupted exception will be thrown in the interrupted thread. If not caught, this will cause the execution of the interrupted thread to terminate. As with any other exception, the stack will be unwound, and destructors for objects of automatic storage duration will be executed.
(boost::this_thread::disable_interruption, Predefined Interruption Points)

Thread IDs
每一个运行中的thread都有一个唯一的id值。
调用对应的boost::thread对象的get_id()方法,或者在运行的thread中调用boost::this_thread::get_id()方法。

Namespace this_thread

this_thread下包含的是在正在运行的线程内部,所能进行的线程操作,包括上面提到的get_id()方法
http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread

Thread Group
thread_group class provides for a collection of threads that are related in some fashion.
New threads can be added to the group with add_thread and create_thread member functions.
thread_group is not copyable or movable.


posted on 2008-04-29 14:25 frank28_nfls 阅读(783) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理