Created
July 5, 2014 10:52
-
-
Save mryoshio/e2572c56732219b00adc to your computer and use it in GitHub Desktop.
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
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