On Oct 26, 2005, at 2:51 PM, Joseph Oreste Bruni wrote:
Hi all,
I seem to have a problem with thread cancelation. I'm using the
pthreads API on OS X 10.4.2 and 10.3.9. The problem appears to be
that threads waiting on a condition variable are not canceled like
they are supposed to be. I've tried both the 4.0 and 3.3 GCC
compilers.
I've tested the same code on HP/UX 11.11, Tru64 4.0f, and Linux and
thread cancelation works on those platforms. It even works on
cygwin on WinXP.
Is this a known issue?
Both POSIX and non-POSIX behaviours are available as of Tiger. The
default behaviour in Tiger is to maintain non-POSIX binary backward
compatibility for programs which are merely recompiled, and would
break if the behaviour suddenly changed to support strict POSIX
interpretation of API definitions.
If you are running on a newer MacOS X (e.g. you are running Tiger/
Cambridge Update), then before including the headers, simply do a:
#define _POSIX_C_SOURCE 200112L
to ask for POSIX standard cancellation behaviour from the threads
APIs. This will also ask all the other API usages for variant APIs
in that compilation unit to have more standard POSIX behaviour, and
it will prevent the prototypes and manifest constants for non-POSIX
APIs being visible, so you may need to break up your compilation
units, if you need to use any non-POSIX APIs.
If you are running an older version of MacOS X, then cancellation
points are explicit... in other words, you have to explicitly call
pthread_testcancel() to create a cancellation point, and not all
interfaces are explicitly cancelable: pthread_cond_wait() is one of
these. The long reason is complicated; the short reason is "because
some frameworks don't expect cancellations of their threads, and
become very upset when they happen because some third party does
something unexpected with an API they use or to one of their threads".
If you want to run code on an older MacOS X, and you know you are not
using any frameworks which will break on an unexpected cancellation
happening under them because of an API you provide, or your explicit
cancelation of one of their threads, do something like:
int
my_pthread_cond_wait(...)
{
...
again:
if (( rv = pthread_cond_timedwait( ... some timeout ...)) ==
-1)
if (errno == ETIMEDOUT) {
pthread_testcancel();
goto again;
}
}
return( rv);
}
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/email@hidden