From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,6d9dcbc18ca0e5d4 X-Google-Attributes: gidfee84,public From: Dave Butenhof Subject: Re: OSF DCE Threads Date: 1996/04/22 Message-ID: <317B8A7E.41C6@zko.dec.com>#1/1 X-Deja-AN: 152257398 references: <4l828e$cio@irz201.inf.tu-dresden.de> content-type: text/plain; charset=us-ascii organization: Digital Equipment Corporation mime-version: 1.0 newsgroups: comp.unix.osf.osf1 x-mailer: Mozilla 2.01 (X11; I; OSF1 P4.0 alpha) > 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" +----------+ +---------------------------------------------+