Skip to content
Snippets Groups Projects
Commit a6bbd0e7 authored by Nadav Har'El's avatar Nadav Har'El Committed by Avi Kivity
Browse files

Fix wake_with()


wake_with(action) was implemented using thread_handle, as the following:

thread_handle h(handle());
action();
h.wake();

This implementation is wrong: It only takes the RCU lock (which prevents
the destruction of _detached_state) during h.wake(), meaning that if the
thread is not sleeping, and action() causes it to exit, _detached_state
may also be destructed, and h.wake() will crash.

thread_handle is simply not needed for wake_with(), and was designed
with a completely different use case in mind (long-term holding of a
thread handler). We just need to use, in-line, the appropriate rcu
lock which keeps _detached_state alive. The resulting code is even
simpler, and nicely parallels the existing code of wake().

This patch fixes a real bug, but unfortunately we don't have a concrete
test-case which it is known to fix.

Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
parent 9f0e1287
No related branches found
No related tags found
No related merge requests found
......@@ -650,9 +650,11 @@ template <class Action>
inline
void thread::wake_with(Action action)
{
thread_handle h(handle());
action();
h.wake();
WITH_LOCK(osv::rcu_read_lock) {
auto ds = _detached_state.get();
action();
wake_impl(ds);
}
}
extern cpu __thread* current_cpu;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment