User Tools

Site Tools


c:c_threads:join

C - C++ Threads - join()

WARNING: std::thread::join() blocks the calling thread.

Calling join on other threads in your main application can cause the application to freeze.

A call to std::thread::join() blocks until the thread on which join is called, has finished executing.

  • A join() in the main() will wait for the execution of the spawned threads to finish before it can exit the application.
  • If join() is not called after creating a thread the main function will not wait for the spawned thread to complete before it tears down the application.
    • If the application tears down before the spawned thread finishes, it will terminate the spawned thread as well, even if it has not finished executing.
    • This can leave data in a very inconsistent state and should be avoided at all cost.

join()

c/c_threads/join.txt · Last modified: 2021/03/05 02:09 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki