Messages in this thread | | | Date | Wed, 23 Sep 2009 12:04:10 -0600 | From | "Chris Friesen" <> | Subject | Re: [RFC] Userspace RCU: (ab)using futexes to save cpu cycles and energy |
| |
On 09/23/2009 11:48 AM, Mathieu Desnoyers wrote:
> Here are the primitives I've created. I'd like to have feedback on my > futex use, just to make sure I did not do any incorrect assumptions.
> /* > * Wake-up any waiting defer thread. Called from many concurrent threads. > */ > static void wake_up_defer(void) > { > if (unlikely(atomic_read(&defer_thread_futex) == -1)) > atomic_set(&defer_thread_futex, 0); > futex(&defer_thread_futex, FUTEX_WAKE, > 0, NULL, NULL, 0); > }
Is it a problem if multiple threads all hit the defer_thread_futex==-1 case simultaneously? If so, maybe this should use an atomic test-and-set operation so that only one thread actually calls futex().
> /* > * Defer thread waiting. Single thread. > */ > static void wait_defer(void) > { > atomic_dec(&defer_thread_futex); > if (atomic_read(&defer_thread_futex) == -1) > futex(&defer_thread_futex, FUTEX_WAIT, -1, > NULL, NULL, 0); > }
Is it a problem if the value of defer_thread_futex changes to zero after the dec but before the test?
Chris
| |