Skip to content

Instantly share code, notes, and snippets.

@codeRhythm
Created August 28, 2018 03:56
Show Gist options
  • Save codeRhythm/7c68f24d3007d1b3e8723d3393ceaa65 to your computer and use it in GitHub Desktop.
Save codeRhythm/7c68f24d3007d1b3e8723d3393ceaa65 to your computer and use it in GitHub Desktop.
using sleep_for

using sleep_for

// thread::get_id / this_thread::get_id
#include <iostream>       // std::cout
#include <thread>         // std::thread, std::thread::id, std::this_thread::get_id
#include <chrono>         // std::chrono::seconds
using namespace std;
void show(int n) {
  if (n==5){
		cout<<"start n=5"<<endl;
		this_thread::sleep_for(chrono::seconds(5));
		cout<<"sleep_for(chrono::seconds(5)) end"<<endl;
	}
  else{
		cout<<"This is not 5"<<endl;
	}
}
 
int main() 
{
	thread t(show,5);
	thread t1(show,100);
	t.join();
	t1.join();	
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment