search

Home  >  Q&A  >  body text

multi-thread - C++11 的 thread 库,为什么没有start方法。

C++11 希望用 thread 库来实现多线程,要启动线程,但thread类为什么没有start方法?
我看网上很多文章都是用join方法来开启线程。join显然是同步的,没达到多线程异步的效果。

大家讲道理大家讲道理2812 days ago1067

reply all(2)I'll reply

  • PHP中文网

    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::threadA new thread starts running when the object is constructed.

    reply
    0
  • PHPz

    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.

    reply
    0
  • Cancelreply