Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thrd_busy and mtx_lock()/mtx_timedlock()

I have the following questions about C1x mutexes (§7.25.4):

In which situations can mtx_lock() return thrd_busy instead of blocking? In which situations can mtx_timedlock() return thrd_busy?

Note that thrd_busy is defined in §7.25.1 ¶5 as being returned "when a resource requested by a test and return function is already in use".

I would expect thrd_busy to be only returned by mtx_trylock(), or at most also by mtx_lock() when invoked with a mtx_try or mtx_try | mtx_recursive mutex, but definitely not from mtx_timedlock(), which requires a mutex which supports timeout, i.e. a mtx_timed or mtx_timed | mtx_recursive mutex.

Is this just and oversight in the draft? Or am I missing something?

like image 505
ninjalj Avatar asked Jun 10 '11 23:06

ninjalj


1 Answers

If the mutex is not recursive, but you try to lock it in a recursive manner then the behaviour is undefined. However, an implementation could detect this and return thrd_busy. (Alternatively, it may block forever, or return thrd_error, or thrd_success, or format your hard disk.....)

like image 136
Anthony Williams Avatar answered Oct 05 '22 22:10

Anthony Williams