[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Thread starvation with mutex



Wan-Teh Chang wrote:
>   The pthread_mutex_unlock() function shall release the mutex
>   object referenced by mutex. The manner in which a mutex is
>   released is dependent upon the mutex's type attribute. If
>   there are threads blocked on the mutex object referenced by
>   mutex when pthread_mutex_unlock() is called, resulting in
>   the mutex becoming available, the scheduling policy shall
>   determine which thread shall acquire the mutex.
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's ambiguous.  The wording implies that some thread _shall_ acquire
the mutex when pthread_mutex_unlock() is called.  It says the
scheduling policy determines which thread.

The starvation example is because pthread_mutex_unlock() is called and
_no_ thread acquires the mutex during that call.  The mutex is
re-acquired later, potentially a long time after
pthread_mutex_unlock() has returned.

You can read the standard as implying that a thread, chosen by the
scheduler, _shall_ acquire the mutex as part of the
pthread_mutex_unlock() operation - a specification that NPTL does not
satisfy.

-- Jamie




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]