Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Dec 2016 15:17:41 +0100
From:      Dimitri Staessens <dimitri.staessens@intec.ugent.be>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: Unlocking a robust mutex in a cleanup handler
Message-ID:  <6a7139cd-b6db-d078-ee5e-b7c590eb13d1@intec.ugent.be>
In-Reply-To: <20161206112558.GN54029@kib.kiev.ua>
References:  <119e59d4-6125-f313-e6e6-67055a15d224@intec.ugent.be> <20161206112558.GN54029@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a7139cd-b6db-d078-ee5e-b7c590eb13d1>