1
General Discussion about just::thread / call to future::wait() aborts the program
« on: May 08, 2013, 04:35:04 PM »
System has 24 logical processors
Compiled under Visual Studio 2012 x64
The same code below runs fine using native Microsoft implementation and fails most of the time when using just::threads
The exact place where it fails is on ftr.wait()
Please advise
for (unsigned i = 0; i < 10; i++)
{
const unsigned THREAD_COUNT = thread::hardware_concurrency() - 1;
const unsigned SECOND_COUNT = 1;
volatile bool runThreads = true;
vector<future<long long>> results;
for (unsigned u = 0; u < THREAD_COUNT; u++)
{
results.emplace_back ( async( [&] ()
{
long long counter = 0;
while (runThreads)
{
counter++;
}
return counter;
} ) );
}
this_thread::sleep_for(chrono::seconds(SECOND_COUNT));
runThreads = false;
long long total = 0;
for (auto& ftr : results)
{
ftr.wait();
total += ftr.get();
}
cout << total << cout << endl;
}
Compiled under Visual Studio 2012 x64
The same code below runs fine using native Microsoft implementation and fails most of the time when using just::threads
The exact place where it fails is on ftr.wait()
Please advise
for (unsigned i = 0; i < 10; i++)
{
const unsigned THREAD_COUNT = thread::hardware_concurrency() - 1;
const unsigned SECOND_COUNT = 1;
volatile bool runThreads = true;
vector<future<long long>> results;
for (unsigned u = 0; u < THREAD_COUNT; u++)
{
results.emplace_back ( async( [&] ()
{
long long counter = 0;
while (runThreads)
{
counter++;
}
return counter;
} ) );
}
this_thread::sleep_for(chrono::seconds(SECOND_COUNT));
runThreads = false;
long long total = 0;
for (auto& ftr : results)
{
ftr.wait();
total += ftr.get();
}
cout << total << cout << endl;
}