boost::thread使用方法
2012-10-01 15:54
302 查看
首先调用thread的构造函数
Default
Effects:
Constructs a
Not-a-Thread.
Throws:
Nothing
解释:这个构造函数并不附加线程,自然无法启动
Thread
Preconditions:
Effects:
into the internals of the thread library that is not of type
Postconditions:
Throws:
Callable可以为一个静态或全局函数指针,也可以是一个拥有operator()函数的类,新建立的线程将会调用该函数或operator(),类似Go()。
Thread
Preconditions:
Effects:
As if
Consequently,
Postconditions:
Throws:
Note:
Currently up to nine additional arguments
调用thread::join()将会执行新线程,该函数会阻塞calling thread直至新线程执行结束
调用thread::timed_join()将会执行新线程,该函数会阻塞calling thread直至传入参数所规定的时间结束
控制运行中的线程
void interrupt();
Namespace
Non-member function
Non-member function
Non-member function
Non-member function
Non-member function
Non-member function
Class
Class
Non-member function template
用于调用当前线程
Class
Constructor
Destructor
Member function
Member function
Member function
Member function
Member function
Member function
用于线程组操作
Default
Constructor
thread();
Effects:
Constructs a
boost::threadinstance that refers to
Not-a-Thread.
Throws:
Nothing
解释:这个构造函数并不附加线程,自然无法启动
Thread
Constructor
template<typename Callable> thread(Callable func);
Preconditions:
Callablemust by copyable.
Effects:
funcis copied into storage managed internally by the thread library, and that copy is invoked on a newly-created thread of execution. If this invocation results in an exception being propagated
into the internals of the thread library that is not of type
boost::thread_interrupted, then
std::terminate()will be called.
Postconditions:
*thisrefers to the newly created thread of execution.
Throws:
boost::thread_resource_errorif an error occurs.
Callable可以为一个静态或全局函数指针,也可以是一个拥有operator()函数的类,新建立的线程将会调用该函数或operator(),类似Go()。
Thread
Constructor with arguments
template <class F,class A1,class A2,...> thread(F f,A1 a1,A2 a2,...);
Preconditions:
Fand each
An must by copyable or movable.
Effects:
As if
thread(boost::bind(f,a1,a2,...)).
Consequently,
fand each
an are copied into internal storage for access by the new thread.
Postconditions:
*thisrefers to the newly created thread of execution.
Throws:
boost::thread_resource_errorif an error occurs.
Note:
Currently up to nine additional arguments
a1to
a9can be specified in addition to the function
f.
调用thread::join()将会执行新线程,该函数会阻塞calling thread直至新线程执行结束
调用thread::timed_join()将会执行新线程,该函数会阻塞calling thread直至传入参数所规定的时间结束
控制运行中的线程
void interrupt();
static void sleep(system_time const& abs_time);
static void yield();
Namespace
this_thread
Non-member functionget_id()
Non-member function
interruption_point()
Non-member function
interruption_requested()
Non-member function
interruption_enabled()
Non-member function
sleep()
Non-member function
yield()
Class
disable_interruption
Class
restore_interruption
Non-member function template
at_thread_exit()
用于调用当前线程
Class
thread_group
ConstructorDestructor
Member function
create_thread()
Member function
add_thread()
Member function
remove_thread()
Member function
join_all()
Member function
interrupt_all()
Member function
size()
#include <boost/thread/thread.hpp> class thread_group: private noncopyable { public: thread_group(); ~thread_group(); template<typename F> thread* create_thread(F threadfunc); void add_thread(thread* thrd); void remove_thread(thread* thrd); void join_all(); void interrupt_all(); int size() const; };
用于线程组操作
相关文章推荐
- Thread_wait、notify、notifyAll的使用方法
- Java Concurrency - ThreadFactory, 使用工厂方法创建线程
- Android 建立线程 Thread详细使用方法
- C++ AfxBeginThread和AfxEndThread 使用方法
- 有关boost安装和使用的一些问题的解决方法
- HandlerThread,Handler,Thread使用方法
- CWinThread的使用方法
- Thread的join方法使用
- boost::thread之while(true)型线程终结方法
- linux下的Boost.Regex的编译和使用方法
- Win10系统中使用VS2017编译Boost1.65的方法
- python 8-1 如何使用多线程,Thread创建线程,执行函数赋值给target//类+函数放在run方法中执行
- 关于线程Thread类中的 Thread(Runnable target) 构造方法的使用
- HandlerThread,Handler,Thread使用方法
- moveToThread的最简单用法(依葫芦画瓢即可)(使得线程也更偏向于信号槽的使用方法)
- Boost 使用方法
- 一种使用QThread线程的新方法QObject::moveToThread
- 一种使用QThread线程的新方法QObject::moveToThread
- [Android] 如何在 Fragment 中使用 runOnUiThread() 方法
- Thread的join方法使用解析