Search notes:

C++ Standard Library: thread::join()

//
//  g++ -std=c++11 join.cpp -lpthread 
//
#include <iostream>
#include <thread>
#include <chrono>

int the_thread() {

  int counter = 0;

  while (counter < 20) {

    std::cout << "The thread is running (counter=" << counter << ")" << std::endl;
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
    counter ++;

  }

}

int main() {

  std::thread t(the_thread);

  t.join();

  std::cout << "t.join() returned, going to sleep for another second" << std::endl;

  std::this_thread::sleep_for(std::chrono::seconds(1));
}
Github repository about-cpp-standard-library, path: /thread/join.cpp

See also

C++ Standard Library

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758193902, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/CPP-Standard-Library/thread/join(68): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78