This is the mail archive of the
mailing list for the Cygwin project.
Re: pthread_mutex_lock doesn't interrupt
- From: Corvus Corax <corvuscorax at cybertrench dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 13 Jul 2010 22:02:57 +0200
- Subject: Re: pthread_mutex_lock doesn't interrupt
> Signal generation and signal delivery aren't the same thing. With
> asynchronous signals as in your test case, there's always some sort of
> delay until the signal is delivered, and I don't know whether the
> standard actually requires any upper bound on that. One example where
> a signal in Cygwin gets deferred is when your thread happens to be
> blocked in a Win32 function (although of course POSIX doesn't apply to
> that anyway).
> Having said all that, if it works in Linux, it ought to work in
> Cygwin. No idea what the issue could be though.
Well as you already said, it could be calling a win32 api function to
implement the mutex_lock and miss the signal because of that.
for that I actually might have a work around - a busy loop with
> while (0!=mutex_trylock()) sched_yield();
You must agree though that's a damn ugly solution just to lock a mutex
in a non signal-blocking way. Busy loops are a no brainer. And due to
other bugs with signaling in combination to sched_yield() as in the
other test case - this isn't even stable right now.
However even pselect() with its sigmask argument explicitly
sigemptyset()-ed does completely block signals and doesn't execute the
pselect() allows the user to specify which signals should be deferred
until the end of pselect() and which should be handled and end
pselect() with errno=EINTR -- and of course also call the signal
I suspect the reason of this behaviour on the entire group of blocking
functions I found (select(), pselect(), pthread_mutex_lock(), ...)
could possibly be the same.
I haven't found any information about how long signals may be deferred
by POSIX functions without explicit definition of signal blockage.
However POSIX usually explicitly defines the functions which may defer
signals - and in many cases even introduces a mask to control that
behaviour. I think it's a safe assumption however that if a signal is
received and a signal handler is set up, the signal handler shall
EVENTUALLY be called unless specified otherwise.
With pthread_mutex_lock() not being released until the signal had been
handled and cygwin not executing the handler until the end of the lock,
the signal is however deferred FOREVER, which brakes this assumption.
One could probably argue that this is not explicitly forbidden by the
POSIX standard, however it's not how Linux or any other semi-posix-like
system works, and it makes certain programming constructs
(in this case a user space scheduler) basically impossible to implement.
Well long story short, I am trying to get a backtrace of the segfault
caused by the other signaling bug with a current debugging enabled
cygwin.dll and post it here, if you don't already have that.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple