C++11 希望用 thread 库来实现多线程,要启动线程,但thread类为什么没有start方法?
我看网上很多文章都是用join方法来开启线程。join显然是同步的,没达到多线程异步的效果。
PHP中文网2017-04-17 14:48:04
std::thread::join()
This function is not used to start a thread. On the contrary, it is used to block the current thread and wait for the corresponding thread to end. std::thread
A new thread starts running when the object is constructed.
PHPz2017-04-17 14:48:04
join()
itself does not start a thread.
Asynchronous access can also be done with async
, paired with std::future
. However, this does not necessarily guarantee that a new thread will be started - unless std::launch::async
is mandatory. It can only guarantee execution during get or wait.