Skip to content

Instantly share code, notes, and snippets.

@juehan
Created February 13, 2012 23:06
Show Gist options
  • Select an option

  • Save juehan/1821322 to your computer and use it in GitHub Desktop.

Select an option

Save juehan/1821322 to your computer and use it in GitHub Desktop.
C++11 Thread Example
#include <thread>
#include <iostream>
int main()
{
auto t1 = new std::thread([]
{
for(int i=0; i < 10; i++)
std::cout<<"Thread 1 ------>"<<std::endl;
});
auto t2 = new std::thread([]
{
for(int i=0; i < 10; i++)
std::cout<<"Thread 2 ------>"<<std::endl;
});
t1->join();
t2->join();
delete t1;
delete t2;
return 0;
}
/* output
Thread 1 ------>Thread 2 ------>
Thread 2 ------>
Thread 1 ------>
Thread 1 ------>
Thread 2 ------>
Thread 2 ------>
Thread 2 ------>
Thread 1 ------>
Thread 2 ------>
Thread 1 ------>
Thread 1 ------>
Thread 2 ------>
Thread 1 ------>
Thread 2 ------>
Thread 1 ------>
Thread 1 ------>
Thread 1 ------>
Thread 2 ------>
Thread 2 ------>
계속하려면 아무 키나 누르십시오 . . .
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment