On Mon, Sep 12, 2016 at 4:29 AM, Ted Unangst <t...@tedunangst.com> wrote: ... > Something feels a little weird about this. Usually you want to keep the rwlock > while sleeping.
Yes, that's usually the point of the lock, but when you need a condition-variable for changes in the state protected by an rwlock, you need rwsleep(). > Instead we use mutex for passing control over sleep. > I don't know how this would make the code look, but something like > > rw_enter(); > /* do a bunch of stuff */ > mtx_enter(); > rw_exit(); > msleep(); So what's protecting the state that you're waiting for the change to occur in? If it's the mutex, then why are you accessing it with only the rwlock early on? If it's the rwlock then how to prevent a lost-wakeup by a thread on another CPU getting in between the rw_exit() and msleep() and calling wakeup() in that window? That code would only work reliably if you held *both* the mutex and the rwlock when making changes to the state, or both the mutex and the big-lock. Either way, what's the point of the rwlock there? Philip Guenther