Author Topic: call to future::wait() aborts the program  (Read 99034 times)

oleg@completedb.com

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • CompleteDB
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;
   }

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: call to future::wait() aborts the program
« Reply #1 on: May 08, 2013, 05:10:17 PM »
I am sorry to hear that you are experiencing problems.

What OS are you running? Which build of VS2012 are you using? (Open a VS2012 command prompt and type "cl") What compiler options are you using?

I cannot reproduce the problem on Windows 7 x64 with VS 2012, build 17.00.50727.1, on a 6-core machine.

I don't have access to a 24-core system just now, but I do have an 8-core one (also running Windows 7). I don't see that the number of cores should make a difference, but I'll try it out in case it does.

oleg@completedb.com

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • CompleteDB
Re: call to future::wait() aborts the program
« Reply #2 on: May 08, 2013, 06:57:40 PM »
OS: Windows 8 Pro
Processors: 2 x Intel Xeon E5-2620
Logical Cores: 24
RAM: 64 GB
Microsoft Visual Studio Professional 2012: Version 11.0.60315.01 Update 2
Build: 17.00.60315.1

C++ Command Line:
/Yu"stdafx.h" /GS /GL /W3 /Gy /Zc:wchar_t /I"C:\Program Files (x86)\JustSoftwareSolutions\JustThread\include" /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc110.pdb" /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\FutureWaitFailed.pch"

For some reason I can not attach the file, wanted to send you Visual Studio solution with source files. If you do not mind I will email it. Its small.
If you run it do not forget to change include and lib path to just thread as on my system it maybe in a different place

oleg@completedb.com

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • CompleteDB
Re: call to future::wait() aborts the program
« Reply #3 on: May 08, 2013, 07:02:19 PM »
Sorry forgot to mention it works on Win32 only fails on x64

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: call to future::wait() aborts the program
« Reply #4 on: May 09, 2013, 08:12:00 AM »
Thank you for the information. I am attempting to recreate the problem.

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: call to future::wait() aborts the program
« Reply #5 on: May 10, 2013, 10:05:16 AM »
After running your test program many times I managed to encounter a problem. It appeared to be a race condition in the internal logic of std::async. I have rewritten the relevant section, and have not encountered any further problems after running the program many more times.

I've added a v1.8.3.1 preview to your package. Please can you download and test.

Cheers,

Anthony

oleg@completedb.com

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • CompleteDB
Re: call to future::wait() aborts the program
« Reply #6 on: May 11, 2013, 12:05:18 AM »
I will test it over weekends and let you know.

Cheers,
Oleg.

oleg@completedb.com

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • CompleteDB
Re: call to future::wait() aborts the program
« Reply #7 on: May 12, 2013, 05:22:19 PM »
The problem is fixed.
Thank you. ;D

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: call to future::wait() aborts the program
« Reply #8 on: May 13, 2013, 07:46:09 AM »
Excellent. I'll roll that out to everyone.