summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorPaul Irofti <pirofti@cvs.openbsd.org>2018-06-08 13:53:02 +0000
committerPaul Irofti <pirofti@cvs.openbsd.org>2018-06-08 13:53:02 +0000
commit4a152d480f9947fdd104aee21e4842cdc30d0cb3 (patch)
tree0039f306a822416c7951036416eb5581120d923b /gnu
parent522d400896b03589ce78f8cd82d94a9942d2e197 (diff)
New semaphore implementation making sem_post async-safe.
POSIX dictates that sem_post() needs to be async-safe here[0] and is thus included in the list of safe functions to call from within a signal handler here[1]. The old semaphore implementation is using spinlocks and __thrsleep to synchronize between threads. Let's say there are two threads: T0 and T1 and the semaphore has V=0. T1 calls sem_wait() and it will now sleep (spinlock) until someone else sem_post()'s. Let's say T0 sends a signal to T1 and exits. The signal handler calls sem_post() which is meant to unblock T1 by incrementing V. With the old semaphore implementation we we are now in a deadlock as sem_post spinlocks on the same lock. The new implementation does not suffer from this defect as it uses futexes to resolve locking and thus sem_post does not need to spin. Besides fixing this defect and making us POSIX compliant, this should also improve performance as there should be less context switching and thus less time spent in the kernel. For architectures that do not provied futexes and atomic operations, the old implementation will be used and it is now being renamed to rthread_sem_compat as discussed with mpi@. [0] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html [1] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html OK visa@, mpi@, guenther@
Diffstat (limited to 'gnu')
0 files changed, 0 insertions, 0 deletions