[haiku-bugs] Re: [Haiku] #11208: POSIX semaphores have incorrect sharing semantics

  • From: "hamish" <trac@xxxxxxxxxxxx>
  • Date: Tue, 12 May 2015 14:58:21 -0000

#11208: POSIX semaphores have incorrect sharing semantics
----------------------------+----------------------------
Reporter: hamish | Owner: nobody
Type: bug | Status: new
Priority: normal | Milestone: Unscheduled
Component: System/POSIX | Version: R1/Development
Resolution: | Keywords:
Blocked By: | Blocking:
Has a Patch: 1 | Platform: All
----------------------------+----------------------------

Comment (by hamish):

They need to be syscalls because they enqueue (or dequeue) the thread in
the global `sUserMutexTable` hashtable (see `user_mutex_wait_locked` in
the patch) for later waking up, which enables implementation of process
shared mutexes and semaphores.

The reason for repeating the atomic ops in kernel space is because it's
done with the `sUserMutexTableLock` lock held, to prevent a race with
someone else releasing the semaphore. With the lock held, a thread
acquiring the semaphore will set it to -1, to mark it as contended. Any
thread releasing the semaphore will then notice this value and use the
system call to release it, and take the same lock when waking up the
original thread.

--
Ticket URL: <https://dev.haiku-os.org/ticket/11208#comment:5>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: