Last active
January 28, 2020 02:42
-
-
Save dulimarta/cb0ec4a5d28cec69d8ec829e9c0d08f5 to your computer and use it in GitHub Desktop.
Lab04 - Sample 1 (C++)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with -lpthread flag | |
#include <iostream> | |
#include <thread> | |
#include <unistd.h> | |
using namespace std; | |
void do_greeting(); | |
int main() { | |
cout << "From PID " << getpid() | |
<< " thread id " << std::this_thread::get_id() << endl; | |
// start thread at a function | |
std::thread one(do_greeting); | |
one.join(); // join() or detach() is required | |
return 0; | |
} | |
void do_greeting() { | |
std::this_thread::sleep_for(chrono::seconds(1)); | |
cout << "Thread version of Hello, world. PID=" << getpid() | |
<< "TID=" << std::this_thread::get_id() << endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment