1

I am developing an application with a realtime context.

One of the threads that executes in realtime context dequeues Task message objects from a mailbox (with real-time capabilities). Those Task messages contain a std::promise and a command.

After the thread gets the Task it executes the command and after that, std::promise::set_value() will be called.

Because of that, I am concerned that calling std::promise::set_value() might not have real-time capability.

Does anybody knows if set::value() internally allocates heap storage or does something else that would break the real-time capability?

Here is some snipplet to hopefully make my question clearer:

void RealTimeThread::exec() { while( active_ ) { Task receivedTask; if( mailbox_.getMailTimed( receivedTask, std::chrono::milliseconds( 100 ) ) ) { try { if( receivedTask.cmd ) { receivedTask.cmd->execute(); } else { // TODO: some internal actions on timeout throw std::runtime_error{"Command invalid"}; } // does the following call has real-time capabilities? receivedTask.cmdPromise.set_value(); } catch( ... ) { receivedTask.cmdPromise.set_exception( std::current_exception() ); } } } } 
3
  • 1
    Aside: you seem to be replicating packaged_task Commented Jan 18, 2018 at 10:19
  • Thank you, that was new to me. Commented Jan 18, 2018 at 10:25
  • It's too bad that nobody can help me :-/ Commented Feb 1, 2018 at 7:49

1 Answer 1

1

If anybody is interested:

A std::promise can be constructed given a allocator. This is used to allocated the "shared state" which is used on the std::future objects.

If you can provide an allocator that allocated on realtime (deterministic) it is fine to use std::promise in such context. Such an allocator is motley allocating from a memory block that was allocated before application entered realtime context.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.