提交 4990b921 编写于 作者: M Matt Pharr

Add Future::TryGet() method

This takes a mutex (that should be held at call time). It returns the
future's value if it's available and otherwise unlocks the mutex, tries to
do some work, and then returns with the mutex re-locked.  This allows
mutex-protected future harvesting to work without deadlock...
上级 da2fd690
......@@ -362,6 +362,15 @@ class Future {
Wait();
return fut.get();
}
pstd::optional<T> TryGet(std::mutex *mutex) {
if (IsReady())
return Get();
mutex->unlock();
DoParallelWork();
mutex->lock();
return {};
}
void Wait() {
while (!IsReady() && DoParallelWork())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册