mutex held in a thread which is cancelled stays busy

Daniel Eischen deischen at freebsd.org
Wed Aug 7 00:58:40 UTC 2019


> On Aug 6, 2019, at 4:54 AM, Erich Dollansky <freebsd.ed.lists at sumeritec.com> wrote:
> 
> Hi,
> 
> for testing purpose, I did the following.
> 
> Start a thread, initialise a mutex in a global variable, lock the mutex
> and wait in that thread.
> 
> Wait in the main program until above's thread waits and cancel it.
> 
> Clean up behind the cancelled thread but leave intentional the mutex
> locked.
> 
> I would have expected now to get an error like 'EOWNERDEAD' doing
> operations with that mutex. But I get 'EBUSY' as the error.

Are you initializing the mutex as a robust mutex, via pthread_mutexattr_setrobust()?  Are you using _lock() or _trylock()?

For _trylock(), you only get EOWNERDEAD for robust mutexes.  It seems that you should get EOWNERDEAD for _lock() in this case, so if that's what you're doing, it sounds like it might be a bug.

--
DE


More information about the freebsd-threads mailing list