I am trying to put futures created asynchronously in a vector, so I don't need to do something like:
auto f1 = async(....); auto f2 = async(....); ... f1.get(); f2.get(); ...
The compilation error that I get with this code is "Calling the remote constructor" std :: _ 1 :: future ". Can someone help me how to do this correctly. Not sure if I copy the future to the vector .
void AudioAnalyzer::retrieve() { deque<shared_ptr<AudioAnalysis>>tempData(data); vector<future<void>> futures; for (int i = 0; i < NUM_THREADS; ++i) { auto f = async(bind(&AudioAnalyzer::analysisThread, this, _1), ref(tempData)); futures.push_back(f); } for (auto& f : futures) { f.get(); } } void AudioAnalyzer::analysisThread(deque<shared_ptr<AudioAnalysis>>& aq ) { while (true) { m.lock(); if (aq.size() == 0) { m.unlock(); break; } auto aa = aq.front(); aq.pop_front(); m.unlock(); if (false)
source share