From owner-freebsd-threads@freebsd.org Wed Aug 7 03:38:54 2019 Return-Path: Delivered-To: freebsd-threads@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 053B2BCA8F; Wed, 7 Aug 2019 03:38:54 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.netplex.net", Issuer "RapidSSL RSA CA 2018" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 463HKn4t7Gz49Dg; Wed, 7 Aug 2019 03:38:53 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from [10.166.221.74] (mobile-107-107-57-103.mycingular.net [107.107.57.103]) (authenticated bits=0) by mail.netplex.net (8.15.1/8.15.1/NETPLEX) with ESMTPSA id x773cpG0048327 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 6 Aug 2019 23:38:52 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.netplex.net [204.213.176.9]); Tue, 06 Aug 2019 23:38:52 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: mutex held in a thread which is cancelled stays busy From: Daniel Eischen X-Mailer: iPhone Mail (16G77) In-Reply-To: <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> Date: Tue, 6 Aug 2019 23:38:51 -0400 Cc: freebsd-questions@freebsd.org, freebsd-threads@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <0CEB9578-74BE-42E7-A612-9A7AE3DBD052@freebsd.org> References: <20190806165429.14bc4052.freebsd.ed.lists@sumeritec.com> <1FC05CEB-982F-484F-9E41-5A74FF564494@freebsd.org> <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> To: Erich Dollansky X-Rspamd-Queue-Id: 463HKn4t7Gz49Dg X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-2.84 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.98)[-0.975,0]; ASN(0.00)[asn:6062, ipnet:204.213.176.0/20, country:US]; NEURAL_HAM_LONG(-0.87)[-0.872,0] X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Aug 2019 03:38:54 -0000 > On Aug 6, 2019, at 9:55 PM, Erich Dollansky wrote: >=20 > Hi, >=20 > On Tue, 6 Aug 2019 20:58:30 -0400 > Daniel Eischen wrote: >=20 >>> On Aug 6, 2019, at 4:54 AM, Erich Dollansky >>> 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=