LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2018, 11:28 PM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Rep: Reputation: Disabled
throw_future_error exception.


Hi,

I am facing std::__throw_future_error(int) () exception if i try to do std::future<bool>::get() ()

Note: this exception is thrown sometimes (2 out of 10 times)

here is my code snippet.

Code:
MyClass::MyClass()
{
   futureNotification = prom.get_future();
}

void* thread_Fun(void *arg)
{
   MyClass *ptr = (MyClass *)arg;

   bool notification = ptr->GetFutureNotification();
 
   if(notification)
   {
     // do relevant work.
   }
}

bool MyClass::GetFutureNotification()
{
   return futureNotification.get();
}

void MyClass::SetNotification()
{
   prom.set_value(true); 
}


class MyClass
{
    std::promise<bool> prom;
    std::future<bool> futureNotification;

  public :

     void SetNotification();  
     bool GetFutureNotification();  

     ...
};
Can anyone let me know why the exception is thrown? Also why this exception is thrown sometimes and not always?

Note : i set the notification (SetNotification) from my other module of program.

My thread function (thread_Fun) will be waiting for notification from GetFutureNotification, when once the promise value is set the thread gets unblocked and proceed with its execution.

I appreciate your support in this regard.
 
Old 04-10-2018, 09:58 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Be sure that you don't have any sort of "race" between the code that sets the future and any other code that expects to assert it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What happens to c++ throw exception? fantasy1215 Programming 3 01-17-2013 09:08 AM
Exception Handling vipinsharma Programming 2 09-25-2005 11:05 AM
help createing exception class from base STL exception qwijibow Programming 4 04-20-2005 05:23 AM
CPU exception zaicheke Linux - Hardware 3 11-26-2004 11:37 AM
Runtime Exception vs. Exception mikeshn Programming 1 09-22-2002 05:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration