HomeFreeBSD

sem_post(): wake up the sleeper only after adjusting has_waiters

Description

sem_post(): wake up the sleeper only after adjusting has_waiters

If the caller of sem_post() wakes up a thread sleeping via sem_wait()
before it clears the has_waiters flag, the caller of sem_wait() has no way of
knowing when it is safe to destroy the semaphore and reuse the memory. This is
because the caller of sem_post() may be interrupted between the wake step and
the clearing of has_waiters. It will then write into the has_waiters flag in
userspace after being preempted for some unknown amount of time.

Reviewed by: jhb, kib, vangyzen
Approved by: kib (mentor), vangyzen (mentor)
MFC after: 2 weeks
Sponsored by: Dell Inc.
Differential Revision: https://reviews.freebsd.org/D7505

Details

Committed
badgerAug 15 2016, 8:09 PM
Reviewer
jhb
Differential Revision
D7505: sem_post(): wake up the sleeper after adjusting has_waiters
Parents
rS304183: dtraceUtil/tst.DataModel32.d.ksh passes on amd64.
Branches
Unknown
Tags
Unknown