Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZqP-e3yzZ2zmsZSu@voyager>
Date: Fri, 26 Jul 2024 21:52:27 +0200
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Cc: JinCheng Li <naiveli233@...look.com>
Subject: Re: Possible unfair scenarios in pthread_mutex_unlock

Am Fri, Jul 26, 2024 at 06:22:50AM +0000 schrieb JinCheng Li:
> Hi
>
> I have two questions in pthread_mutex_unlock.
>
>   1.
> Why we need a vmlock in only pshared mutex, not in other private mutex?

Because only in the pshared case it is valid to have the mutex in a
shared memory, and unmap the shared memory immediately following an
unlock.

>   2.
> For pshared mutex, after swap _m_lock to unlock state, we need to wait
> for vmunlock before wake other waiters. During this period, if someone
> trylocks this pshared lock, queue jumping may occur. Is this unfair to
> the preious waiters? They may have to wait longer to get woken up.
> This can cause performance issues, do we have any good way to avoid
> this?

Fairness is not guaranteed for mutexes. It is not guaranteed for
anything. For any synchronization primitives, someone can snipe it. In a
situation where you constantly have new waiters coming into the mutex,
it is not guaranteed that any one waiter won't starve.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.