Date: Tue, 6 Aug 2019 23:38:51 -0400 From: Daniel Eischen <deischen@freebsd.org> To: Erich Dollansky <freebsd.ed.lists@sumeritec.com> Cc: freebsd-questions@freebsd.org, freebsd-threads@freebsd.org Subject: Re: mutex held in a thread which is cancelled stays busy Message-ID: <0CEB9578-74BE-42E7-A612-9A7AE3DBD052@freebsd.org> In-Reply-To: <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> References: <20190806165429.14bc4052.freebsd.ed.lists@sumeritec.com> <1FC05CEB-982F-484F-9E41-5A74FF564494@freebsd.org> <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> On Aug 6, 2019, at 9:55 PM, Erich Dollansky <freebsd.ed.lists@sumeritec.co= m> wrote: >=20 > Hi, >=20 > On Tue, 6 Aug 2019 20:58:30 -0400 > Daniel Eischen <deischen@freebsd.org> wrote: >=20 >>> On Aug 6, 2019, at 4:54 AM, Erich Dollansky >>> <freebsd.ed.lists@sumeritec.com> wrote: >>>=20 >>> Hi, >>>=20 >>> for testing purpose, I did the following. >>>=20 >>> Start a thread, initialise a mutex in a global variable, lock the >>> mutex and wait in that thread. >>>=20 >>> Wait in the main program until above's thread waits and cancel it. >>>=20 >>> Clean up behind the cancelled thread but leave intentional the mutex >>> locked. >>>=20 >>> I would have expected now to get an error like 'EOWNERDEAD' doing >>> operations with that mutex. But I get 'EBUSY' as the error. =20 >>=20 >> Are you initializing the mutex as a robust mutex, via >> pthread_mutexattr_setrobust()? Are you using _lock() or _trylock()? >>=20 >> 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. >>=20 > I did both. One time with initialising the mutex with its defaults by > handing over NULL as the attribute setting and one time with the > attributes set. >=20 > I use this line to set the attribute: >=20 > pres =3D pthread_mutexattr_setrobust (& Attr, PTHREAD_MUTEX_ROBUST); >=20 > The following line: >=20 > pthread_mutexattr_getrobust (& Attr, &pres); >=20 > Sets pres also to 1. >=20 > I am doing this on 12.0-STABLE FreeBSD 12.0-STABLE r350391 GENERIC > amd64 with the systems standard compiler. >=20 > Is this the corrent way of doing it? Yes, I believe so. I'm curious if the bug also exists in -current. -- DE=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0CEB9578-74BE-42E7-A612-9A7AE3DBD052>