Skip to content

Instantly share code, notes, and snippets.

@mryoshio
Created July 5, 2014 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mryoshio/e2572c56732219b00adc to your computer and use it in GitHub Desktop.
Save mryoshio/e2572c56732219b00adc to your computer and use it in GitHub Desktop.
double accum(double* beg, double* end, double init)
{
return accumulate(beg, end, init);
}
double comp2(vector<double>& v)
{
using Task_type = double(double*, double*, double);
packaged_task<Task_type> pt0 { accum }; // タスク(i.e., accum)をパッケージ化
packaged_task<Task_type> pt1 { accum };
future<double> f0 { pt0.get_future() }; // pt0のfutureを保持
future<double> f1 { pt1.get_future() }; // pt1のfutureを保持
double* first = &v[0];
thread t1 { move(pt0), first, first + v.size()/2, 0 }; // pt0向けスレッドを開始
thread t2 { move(pt1), first, first + v.size()/2, 0 }; // pt1向けスレッドを開始
//...
return f0.get() + f1.get(); // 結果を取得
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment