Skip to content

Instantly share code, notes, and snippets.

@yasukei
Created April 24, 2020 12:04
Show Gist options
  • Save yasukei/b2c4aeb1eecd137f51d4e47b98f239f8 to your computer and use it in GitHub Desktop.
Save yasukei/b2c4aeb1eecd137f51d4e47b98f239f8 to your computer and use it in GitHub Desktop.
std::future
#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;
}
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