From owner-freebsd-threads@freebsd.org Tue Dec 6 11:26:04 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 C68FAC692D4 for ; Tue, 6 Dec 2016 11:26:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4460F12EC for ; Tue, 6 Dec 2016 11:26:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id uB6BPwbK063341 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 6 Dec 2016 13:25:58 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua uB6BPwbK063341 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id uB6BPw6M063292; Tue, 6 Dec 2016 13:25:58 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 6 Dec 2016 13:25:58 +0200 From: Konstantin Belousov To: Dimitri Staessens Cc: freebsd-threads@freebsd.org Subject: Re: Unlocking a robust mutex in a cleanup handler Message-ID: <20161206112558.GN54029@kib.kiev.ua> References: <119e59d4-6125-f313-e6e6-67055a15d224@intec.ugent.be> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <119e59d4-6125-f313-e6e6-67055a15d224@intec.ugent.be> User-Agent: Mutt/1.7.1 (2016-10-04) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home 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 11:26:04 -0000 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.