Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Dave Butenhof <butenhof@zko.dec.com>
Subject: Re: OSF DCE Threads
Date: 1996/04/22	[thread overview]
Message-ID: <317B8A7E.41C6@zko.dec.com> (raw)
In-Reply-To: 4l828e$cio@irz201.inf.tu-dresden.de


> I wrote a program which creates a single thread. The thread
> only makes a printf(..) in an endless loop.
> 
> A pthread_cancel(...) delivered to these thread causes the
> program to halt - not only the thread. Why ?
> 
> Following test program runs on a DEC ALPHA. Operation System
> Version is DEC OSF/1 V3.2A  (Rev. 17).
> 
> Compiled and linked:
> gcc thread.c -Wall -ldce -lpthreads -lmach -lc_r -lm \
> -D_SHARED_LIBRARIES -I. -Dalpha -D_REENTRANT
> 
> 
> Christof.

You didn't say what the failure mode was. Out of sheer curiosity, I
tried the program, and I got a hang. No matter -- it could be all sorts
of things depending upon exactly what the thread is doing when the
cancel arrives.

The program is ILLEGAL. You cannot call anything in the C library with
asynchronous cancellation enabled. In fact, you cannot call anything
with asynchronous cancellation enabled except the functions to DISABLE
asynchronous cancellation -- and any functions you may code to be async
cancel safe (and if they do anything "interesting", they'll be async
cancel safe only because they start out by disabling async
cancellation).

Code that allocates resources (malloc, locking mutexes, etc.) is
completely blown out of the water by async cancel, because there's no
reliable way to determine whether the resources were acquired, and
therefore no way to clean up. In your case, you probably left some libc
state inconsistent, resulting in an error (segv, perhaps?) when it was
next touched (perhaps during process rundown). In my case, it probably
caught printf with a mutex locked, and process rundown blocked on that
mutex (which will never be released since the thread is gone).

If you're calling anything, you must rely on synchronous cancellation
only. POSIX 1003.1c-1995 doesn't require printf to be a cancellation
point, so a portable program cannot rely on synchronous cancellation.
And, in any case, DEC OSF/1 3.2 didn't implement 1003.1c-1995 -- it has
"DCE threads", which implement an older draft that didn't specify
cancellation points, and since DCE threads wasn't tightly integrated
with the O/S, there were no cancellation points outside of the threads
library in any case.

I assume you noticed this, and decided to try asynchronous cancellation
as a "workaround". I've been informed before that the "DCE porting
guide" advised trying async cancellation to allow cancellation of system
calls -- perhaps you read that or heard about it. It was irresponsible
advice, and you'll get yourself in trouble 99% of the time if you try
it. In any case, it doesn't apply to any stdio functions, none of which
are system calls.

+-------------------------------------------------------------------+
| Dave Butenhof                       Digital Equipment Corporation |
| butenhof@zko.dec.com                110 Spit Brook Rd, ZKO2-3/Q18 |
| PH 603.881.2218, FAX 603.881.0120   Nashua, NH 03062-2711         |
+----------+     "Better Living Through Concurrency"     +----------+
           +---------------------------------------------+



      reply	other threads:[~1996-04-22  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-19  4:00 OSF DCE Threads Christof Sieber
1996-04-22  4:00 ` Dave Butenhof [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox