From owner-freebsd-questions@freebsd.org Wed Aug 7 01:56:20 2019 Return-Path: Delivered-To: freebsd-questions@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 738ADBA88C for ; Wed, 7 Aug 2019 01:56:20 +0000 (UTC) (envelope-from freebsd.ed.lists@sumeritec.com) Received: from out2-4.antispamcloud.com (out2-4.antispamcloud.com [185.201.17.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 463F3S2H5qz440h; Wed, 7 Aug 2019 01:56:19 +0000 (UTC) (envelope-from freebsd.ed.lists@sumeritec.com) Received: from srv31.niagahoster.com ([153.92.8.106]) by mx62.antispamcloud.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hvBBY-0001jh-IT; Wed, 07 Aug 2019 03:56:18 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sumeritec.com; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1e78t4imKpgUmFxG2B5GuLtxc9x7+/NJa3kdb6vDPt0=; b=rF7ysYRbs9NaWWAuMIgra2Ruky 2e08kZcEEgBumv7P5guLigAa5fBPCaZPBBblyZUul4iYUy4IQeY765vSoU+kFSSoH1tqat9jxTgO9 TqumBBWORMmPY5SVgnIbxDFyLTSMGOXQ06fqQcdpHprxzhoyY7vTkrAbm41xCX59yI3H2QZBIP8aV vcn73HnbIec5BN0oonJwMKTlyBIWU1XYqFqaXyzNKitqPQiHz6zc3xuKW5guu++rYXLeSH3qLxsrU MyDw/oqxZiEW9viio0pOT/JRIEPV5gGM8pNKidZWvfJW5SAlZ4wnqOMt8k7NkTR9EPDBejsAiBpbB Zgum7jkg==; Received: from [114.125.104.25] (port=40395 helo=Ryzen1.sumeritec.com) by srv31.niagahoster.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hvBAh-0009xs-F4; Wed, 07 Aug 2019 08:55:29 +0700 Date: Wed, 7 Aug 2019 09:55:21 +0800 From: Erich Dollansky To: Daniel Eischen Cc: freebsd-threads@freebsd.org, freebsd-questions@freebsd.org Subject: Re: mutex held in a thread which is cancelled stays busy Message-ID: <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> In-Reply-To: <1FC05CEB-982F-484F-9E41-5A74FF564494@freebsd.org> References: <20190806165429.14bc4052.freebsd.ed.lists@sumeritec.com> <1FC05CEB-982F-484F-9E41-5A74FF564494@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-1.0 X-AuthUser: freebsd.ed.lists@sumeritec.com X-Originating-IP: 153.92.8.106 X-Spampanel-Domain: out.niagahoster.com X-Spampanel-Username: niaga X-Spampanel-Outgoing-Class: unsure X-Spampanel-Outgoing-Evidence: Combined (0.10) X-Recommended-Action: accept X-Filter-ID: Mvzo4OR0dZXEDF/gcnlw0YiRRkpbHZ8F3zevhEShTfypSDasLI4SayDByyq9LIhVcXSMTL9HkUMo SGLCNdCGjkTNWdUk1Ol2OGx3IfrIJKyP9eGNFz9TW9u+Jt8z2T3KSZWQ0mYy/5bX2tR2MxjY1He4 QIvBAg3toE6wd3PtFST6QG6oDWQr5qk8z/hipQQV8BnYfpDYZuPUHQ4+kRclmut3X8qJIxoEnWnh Z3Z4EQ0EybI1sOftHmSKUCHCvcq0TzZjnkrrL1mACMw/UF0G0YY2nx1cxH3HU+PdSK79lGxlwCIq IFS/mFDdwByP9xvkiFKfD1jKgYfH+6S5qDVYoHMsWssqp2lt1msloY8jIytZBppJJpFwVMXFpG8A OA64V0BTl9HMz9DNBb38igffcAbwQK4LAQJrMLA4O04Xvw+LJASz52UZdQktZn4ZzTw2aWWR7drM d0qbJIo1RVCXie2VXGdtLyog7ui50fJvZPWymVBEglNuNDdi9xAbizrH5OsVdOhXIGZEKBBVfrNX IVS7yrN4xA/q5McvR31SN9j/k1N3tK79oubV/+cOjvsnVgW9/bktU41htiJ8fk7NkNwbqGxFBmIA iDD7PzfsCqBft7Ajx7WHtEhOA3XgEeYZW39F4n0x+HPOZspMfvAj0YRTW602yRQA5EJXZYVlfSMC REzfnoFC6n4OhPINd4JYiRnjw/yazDFYILBfUFtypNfW/NFkpeAnOL+dmWwczcN/uZMLhgfeg7qI /OGW6RghMzg958IFbKKlNc0N5cagQhEVniihuDwEGDcmr6e3OPR6sTg77M0R+x8fsZyY3r6hhtDd uEmQaNsuP6MC13FFFhmqMsV06mxfYj+GMh+J0s3oGIU/PTbWBECV59LK0QpTUV8ShebT8U8Xw9HT DfreWfMdEG+w4w+UCBj80AzHFeE4XjD8YIRbIyMCDTapG1wv+PkEjlaMIKgdxNnS2I5dkIU7rv9S DguAeTunaCXFDs4WM6T6hgb0dJLNfyKLko5LifnL+9wgoTj4ygNPw1XfNxMQN11Phz3Ne8+Pf6jt WO02wSOXSHf4/MYvYKEiKwpEGJdimYZGouioJWKkMaVHGnBqz7TRiWF91U/smddrJvE= X-Report-Abuse-To: spam@quarantine10.antispamcloud.com X-Rspamd-Queue-Id: 463F3S2H5qz440h X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-6.96 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.966,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-0.997,0] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Aug 2019 01:56:20 -0000 Hi, On Tue, 6 Aug 2019 20:58:30 -0400 Daniel Eischen wrote: > > On Aug 6, 2019, at 4:54 AM, Erich Dollansky > > 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. > 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. I use this line to set the attribute: pres = pthread_mutexattr_setrobust (& Attr, PTHREAD_MUTEX_ROBUST); The following line: pthread_mutexattr_getrobust (& Attr, &pres); Sets pres also to 1. I am doing this on 12.0-STABLE FreeBSD 12.0-STABLE r350391 GENERIC amd64 with the systems standard compiler. Is this the corrent way of doing it? Erich