【发布时间】:2018-06-27 08:27:39
【问题描述】:
我正在开发一个具有实时上下文的应用程序。
在实时上下文中执行的线程之一将Task 消息对象从邮箱中取出(具有实时功能)。那些Task 消息包含std::promise 和command。
线程获取Task后执行命令,然后调用std::promise::set_value()。
因此,我担心调用std::promise::set_value() 可能没有实时功能。
有人知道set::value() 是在内部分配堆存储还是做了其他会破坏实时能力的事情?
这里有一些snipplet,希望能让我的问题更清楚:
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() );
}
}
}
}
【问题讨论】:
-
旁白:你似乎在复制packaged_task
-
谢谢,这对我来说是新的。
-
太糟糕了,没有人可以帮助我:-/
标签: c++11 promise c++14 real-time