Created
February 13, 2012 23:06
-
-
Save juehan/1821322 to your computer and use it in GitHub Desktop.
C++11 Thread Example
This file contains hidden or 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
| #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