* OSF DCE Threads
@ 1996-04-19 4:00 Christof Sieber
1996-04-22 4:00 ` Dave Butenhof
0 siblings, 1 reply; 2+ messages in thread
From: Christof Sieber @ 1996-04-19 4:00 UTC (permalink / raw)
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.
#include <stdio.h>
#include <dce/pthread.h>
unsigned long operation(pthread_addr_t arg)
{
unsigned long *p = (unsigned long*)arg;
if (pthread_setcancel (CANCEL_ON) == -1)
printf("pthread_setcancel failed.\n");
if (pthread_setasynccancel (CANCEL_ON) == -1)
printf("pthread_setasynccancel failed.\n");
while (1) {
printf("Thread %ld\n", *p);
}
}
int main()
{
pthread_t thread;
unsigned long ulArg;
struct timespec time;
time.tv_sec = 1;
time.tv_nsec = 0;
ulArg = 1;
if (pthread_create (&thread, pthread_attr_default,
(pthread_startroutine_t)operation,
(pthread_addr_t)&ulArg) == -1) {
printf("pthread_create failed.\n");
}
pthread_delay_np(&time);
pthread_cancel(thread);
pthread_delay_np(&time);
printf("Process finished.\n");
return(0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: OSF DCE Threads
1996-04-19 4:00 OSF DCE Threads Christof Sieber
@ 1996-04-22 4:00 ` Dave Butenhof
0 siblings, 0 replies; 2+ messages in thread
From: Dave Butenhof @ 1996-04-22 4:00 UTC (permalink / raw)
> 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" +----------+
+---------------------------------------------+
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-04-22 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-19 4:00 OSF DCE Threads Christof Sieber
1996-04-22 4:00 ` Dave Butenhof
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox