私は一度も使ったことのないstd :: threadを使うことができますが、かなり簡単です。
はここcppreference.comで見つかった簡単なプログラムの例です:
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
// simulate expensive operation
std::this_thread::sleep_for(std::chrono::seconds(1));
}
void bar()
{
// simulate expensive operation
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::cout << "starting first helper...\n";
std::thread helper1(foo);
std::cout << "starting second helper...\n";
std::thread helper2(bar);
std::cout << "waiting for helpers to finish...\n";
helper1.join();
helper2.join();
std::cout << "done!\n";
}
あなたは、スレッドが終了するのを待つために参加する()関数を使用することができます。 たとえば、タスクAを実行する新しいスレッドを作成します。その後、タスクBを実行する新しいスレッドを作成する前に終了します。
g ++ -std = C++ 0x- pthread main.cpp
また、いくつかの可能性を提供できるMPIとOpenMPを検索することもできます。
ハングオン - 私は以前これをどこかで見ましたか? –
[N3558](http://open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3558.pdf)が承認されれば、これは 'auto flow = std :: when_all (std :: async(E)); '(std :: async(D))を実行します。 – Xeo
@Xeoとてもいいです! Boost 1.54.0(現在はベータ版)のBoost.Threadでほとんど同じことができますが、自分でwhen_allを実装する必要があります。それは.then()を提供します(不完全ですが、エグゼキュータを変更する必要がない場合は動作するはずです)。 – Klaim