cpp11/thread.cc

18 lines
510 B
C++
Raw Normal View History

2012-05-25 09:06:00 -07:00
// based on: http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/
2012-05-05 08:34:15 -07:00
#include <iostream>
#include <thread>
void call_from_thread() {
2012-05-25 09:06:00 -07:00
std::cout << "sleeping in the thread" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "finishing in thread" << std::endl;
2012-05-05 08:34:15 -07:00
}
int main() {
std::thread t1(call_from_thread);
2012-05-25 09:06:00 -07:00
std::cout << "printing from original thread" << std::endl;
2012-05-05 08:34:15 -07:00
t1.join();
2012-05-25 09:06:00 -07:00
std::cout << "after join" << std::endl;
2012-05-05 08:34:15 -07:00
return 0;
}