#include <iostream>#include <thread> void doWork(){ while(true) { // Do some work; sleep(1); // Rest std::cout << "hi from worker." << std::endl; }} int main(int, char**){ std::thread worker(&doWork); std::cout << "hello from main thread, the worker thread is busy." << std::endl; worker.join(); return 0;}
Standard input is empty
hello from main thread, the worker thread is busy. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker. hi from worker.
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!