Created
April 24, 2020 12:04
-
-
Save yasukei/b2c4aeb1eecd137f51d4e47b98f239f8 to your computer and use it in GitHub Desktop.
std::future
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
#include <cstdio> | |
#include <string> | |
#include <future> | |
int main() | |
{ | |
auto f = [](std::string threadName) { | |
for (int i = 0; i < 10; i++) | |
{ | |
printf("threadName: [%s], i: [%d]\n", threadName.c_str(), i); | |
} | |
}; | |
std::future<void> future1 = std::async(f, "thread1"); | |
printf("before join\n"); | |
future1.wait(); | |
printf("after join\n"); | |
return 0; | |
} |
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
before join | |
threadName: [thread1], i: [0] | |
threadName: [thread1], i: [1] | |
threadName: [thread1], i: [2] | |
threadName: [thread1], i: [3] | |
threadName: [thread1], i: [4] | |
threadName: [thread1], i: [5] | |
threadName: [thread1], i: [6] | |
threadName: [thread1], i: [7] | |
threadName: [thread1], i: [8] | |
threadName: [thread1], i: [9] | |
after join | |
続行するには何かキーを押してください . . . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment