New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing held locks #1697
Fixing held locks #1697
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,6 +300,13 @@ namespace detail | |
wait(ec); | ||
if (ec) return NULL; | ||
|
||
// No locking is required. Once a future has been made ready, which | ||
// is a postcondition of wait, either: | ||
// | ||
// - there is only one writer (future), or | ||
// - there are multiple readers only (shared_future, lock hurts | ||
// concurrency) | ||
|
||
if (state_ == empty) { | ||
// the value has already been moved out of this future | ||
HPX_THROWS_IF(ec, no_state, | ||
|
@@ -309,7 +316,7 @@ namespace detail | |
} | ||
|
||
// the thread has been re-activated by one of the actions | ||
// supported by this promise (see \a promise::set_event | ||
// supported by this promise (see promise::set_event | ||
// and promise::set_exception). | ||
if (state_ == exception) | ||
{ | ||
|
@@ -388,6 +395,7 @@ namespace detail | |
|
||
// check whether the data has already been set | ||
if (is_ready_locked()) { | ||
l.unlock(); | ||
HPX_THROWS_IF(ec, promise_already_satisfied, | ||
"future_data::set_value", | ||
"data has already been set for this future"); | ||
|
@@ -423,6 +431,7 @@ namespace detail | |
|
||
// check whether the data has already been set | ||
if (is_ready_locked()) { | ||
l.unlock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THROWS might suspend as the stack is collected on a different HPX thread under certain circumstances, this has nothing to do with the problem at hand, it's just a fly-by. |
||
HPX_THROWS_IF(ec, promise_already_satisfied, | ||
"future_data::set_exception", | ||
"data has already been set for this future"); | ||
|
@@ -436,7 +445,8 @@ namespace detail | |
// set the data | ||
boost::exception_ptr* exception_ptr = | ||
static_cast<boost::exception_ptr*>(storage_.address()); | ||
::new ((void*)exception_ptr) boost::exception_ptr(std::forward<Target>(data)); | ||
::new ((void*)exception_ptr) boost::exception_ptr( | ||
std::forward<Target>(data)); | ||
state_ = exception; | ||
|
||
// handle all threads waiting for the future to become ready | ||
|
@@ -489,7 +499,8 @@ namespace detail | |
/// operation. Allows any subsequent set_data operation to succeed. | ||
void reset(error_code& /*ec*/ = throws) | ||
{ | ||
boost::unique_lock<mutex_type> l(this->mtx_); | ||
// no locking is required as semantics guarantee a single writer | ||
// and no reader | ||
|
||
// release any stored data and callback functions | ||
switch (state_) { | ||
|
@@ -509,6 +520,7 @@ namespace detail | |
} | ||
default: break; | ||
} | ||
|
||
state_ = empty; | ||
on_completed_ = completed_callback_type(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code can only be executed on a precondition violation, which would point to bugs elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it's an unrelated change.