From owner-freebsd-threads@freebsd.org Tue Dec 6 14:20:16 2016 Return-Path: Delivered-To: freebsd-threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E27D9C6962C for ; Tue, 6 Dec 2016 14:20:16 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from smtp2.ugent.be (smtp2.ugent.be [157.193.49.126]) (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 A4B749AB for ; Tue, 6 Dec 2016 14:20:16 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from localhost (mcheck3.ugent.be [157.193.71.89]) by smtp2.ugent.be (Postfix) with ESMTP id 80201B210E; Tue, 6 Dec 2016 15:20:13 +0100 (CET) X-Virus-Scanned: by UGent DICT Received: from smtp2.ugent.be ([157.193.49.126]) by localhost (mcheck3.ugent.be [157.193.43.11]) (amavisd-new, port 10024) with ESMTP id YelxjzOLM51m; Tue, 6 Dec 2016 15:20:13 +0100 (CET) Received: from mail2.intec.ugent.be (mail2.intec.ugent.be [157.193.214.245]) by smtp2.ugent.be (Postfix) with ESMTP id 18FDFB2300; Tue, 6 Dec 2016 15:20:13 +0100 (CET) Received: from [10.10.131.46] (hal.ilabt.iminds.be [193.191.148.129]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dstaesse) by mail2.intec.ugent.be (Postfix) with ESMTPSA id EA4EE2C; Tue, 6 Dec 2016 15:20:12 +0100 (CET) Subject: Re: Unlocking a robust mutex in a cleanup handler To: Konstantin Belousov References: <119e59d4-6125-f313-e6e6-67055a15d224@intec.ugent.be> <20161206112558.GN54029@kib.kiev.ua> Cc: freebsd-threads@freebsd.org From: Dimitri Staessens Message-ID: <6a7139cd-b6db-d078-ee5e-b7c590eb13d1@intec.ugent.be> Date: Tue, 6 Dec 2016 15:17:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20161206112558.GN54029@kib.kiev.ua> X-Miltered: at jchkm3 with ID 5846C91D.001 by Joe's j-chkmail (http://helpdesk.ugent.be/email/)! X-j-chkmail-Enveloppe: 5846C91D.001 from mail2.intec.ugent.be/mail2.intec.ugent.be/157.193.214.245/mail2.intec.ugent.be/ X-j-chkmail-Score: MSGID : 5846C91D.001 on smtp2.ugent.be : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Status: Ham Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 14:20:17 -0000 Dear Konstantin, thanks for your immediate response. Please find attached a minimal code example. I do hope I'm sending in the correct format, I'm new to the community. The test creates an integer, robust mutex and condition variable in shared memory. A thread blocks on that condition variable with the associated mutex. After one second, the main thread cancels the blocking thread. I compile as follows: gcc robust_test.c -lpthread -lrt -o robust_test and run ./robust_test On linux it gives the following output: [dstaesse@phoneutria]$ ./robust_test Initializing... Starting thread... Sleeping for one second... Thread started... Cancelling thread... Thread finished. Bye. On FreeBSD I get the following: $ ./robust_test Initializing... Starting thread... Sleeping for one second... Thread started... Cancelling thread... Fatal error 'inact_mtx enter' at line 188 in file /usr/src/lib/libthr/thread/thr_mutex.c (errno = 0) Abort trap (core dumped) Thanks again for your time, Dimitri On 12/06/16 12:25, Konstantin Belousov wrote: > On Tue, Dec 06, 2016 at 11:49:24AM +0100, Dimitri Staessens wrote: >> Dear devs, >> >> first of all, thank you for supporting robust mutexes in FreeBSD 11. >> >> I'm having some issues with a thread that holds a robust mutex (residing >> in a POSIX shared memory (shm) segment) in conjunctions with a condition >> variable (also in that POSIX shm) on which that thread is blocked via a >> pthread_cond_wait() call. pthread_cond_wait tries to retake the mutex >> after the thread cancellation signal is received, and there is a >> pthread_mutex_unlock pushed to the cleanup stack to unlock that robust >> mutex in case of a cancellation. >> >> Cancelling that thread works fine on Linux, however, on FreeBSD >> 11.0-RELEASE, if I pthread_cancel that thread I can't get past the >> following check and resulting PANIC call: >> https://github.com/freebsd/freebsd/blob/master/lib/libthr/thread/thr_mutex.c#L187 >> >> After removing the check and recompiling libthr everything seems to work >> fine. >> >> Could this be a bug in libthr or am I missing a nuance in the use of a >> shared robust mutexes in conjunction with condition variables? > Most likely, this is a bug in libthr. But please extract the minimal > reproduction case and send it to me. -- Dimitri Staessens Ghent University - imec Dept. of Information Technology (INTEC) Internet Based Communication Networks and Services Technologiepark 15 9052 Zwijnaarde T: +32 9 331 48 70 F: +32 9 331 48 99