mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Memory lock needed for semaphores?
@ 2024-08-04  7:29 Markus Wichmann
  2024-08-04 13:31 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Markus Wichmann @ 2024-08-04  7:29 UTC (permalink / raw)
  To: musl

Hi all,

in the light of the recent thread about barriers I looked at the
semaphore implementation under the light of the sudden unmap issue
again. To recap, the issue is that multiple threads may interact with
the same pshared semaphore, and in particular one thread might unmap a
semaphore that another thread is currently still interacting with.

Is that an issue with semaphores? I'm thinking of the following
scenario:

Start: One thread of another process is blocked at the semaphore
(sem->__val = {INT_MIN, 1, 0}).

Thread 1: Calls sem_post(), gets until just after the a_cas() before
being preempted (sem->__val = {1, 1, 0}, but this thread saw val < 0 and
waiters <= 1, so broadcast wake will issue once thread resumes).

Thread 2: Calls sem_trywait(), sets sem->__val = {0, 1, 0}.
Thread 2: Calls sem_post(), sets sem->__val = {1, 1, 0}, does not wake.
Thread 2: Unmaps the semaphore.
Thread 1: Resumes. SYS_futex returns EFAULT. Other process remains
sleeping.

Am I missing something that makes this impossible? If not, do we maybe
need a vmlock for posting pshared semaphores? That would probably be the
easiest fix.

Ciao,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-08-11  4:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-04  7:29 [musl] Memory lock needed for semaphores? Markus Wichmann
2024-08-04 13:31 ` Rich Felker
2024-08-04 22:40   ` Rich Felker
2024-08-07  7:15     ` Markus Wichmann
2024-08-10  3:02       ` Rich Felker
2024-08-10 20:47     ` Rich Felker
2024-08-11  4:40       ` Markus Wichmann

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).