>>>
Here is the testcase to recreate the problem:
>>You omitted the testcase!
I did not omit the testcase. I attached the testcase,
not sure whether you received it or not. Here is the same
testcases(inline): ----------------------------------------------------------------------- /* Compilation line: gcc -o server multiple_pthread_cancel.c
-lpthread */
/* This Thread2 simply blocks at getchar() and waits
for cancel from Thread3 and handles it. After handling that cancel this Thread2
again goes back and
waits at getchar() and waits for another cancel signal.
*/
int i=1; jmp_buf jmp; struct _pthread_cleanup_buffer _buffer; while(1) { _pthread_cleanup_push(&_buffer,
jump_back, &jmp); if(!_setjmp (jmp)) { printf("\tT2: Thread2_StartRoutine:
Blocking on getchar()\n"); getchar(); _pthread_cleanup_pop(&_buffer,
0); } else { printf("\tT2: Thread2_StartRoutine:
Got a jump\n"); /* For AIX we need to add the
following line to make it work: pthread_clear_exit_np(pthread_self()); */ /* For SOLARIS we need to add
the following line to make it work: pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,
&__cstate); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,
&__ctype); */ /* for Linux ???? What is the equivalent code
???? */ } } }
int main(int argc, char *argv[]) {
/* This main function creates Thread2 and Thread3
and does join on them */
> I am facing a problem in a multithread program where I send multiple
> pthread_cancels
> to a same thread from another thread.
Sounds like no "problem", but like misunderstanding.. You
_cannot_
"send" multiple cancels!
> In the first thread Iam catching
> this
> pthread_cancel signal and returning to normal operation as if cancel
> signal has not come.
> This application works fine on Aix and Solaris but on Linux(redhat
9
> Kernel version 2.4.20-8)
> it is not working.
Thread cancellation is _not_ like a signal. It's semantics are rather
different. With LinuxThreads, cancellation is actually realized with
a signal _internally_, but that doesn't change the semantics.
> I would be greatful for your help and inputs in this regard.
>
> I could recreate this problem with native pthread calls and setjmp/longjmp
> calls. The
> following mail gives complete information about the problem.
>
> Here is the testcase to recreate the problem:
You omitted the testcase!
However, I suspect that when you do multiple pthread_cancel()s, the
thread is _gone_ on Linux by the time you perform the second
pthread_cancel() call. This is most probably how it should be.
> The pthread_clear_exit_np() function clears the exit status of the
thread.
...
> This function is not portable
... and it is not available on Linux. (I'd like to add: _fortunately_
it is not available, as I absolutely cannot see a point in it)
> Is there any alternative(or any APIs available) here to make above
> testcase
> to run with expected o/p similar to AIX/SOLARIS. Can you pls let me
know
> where
> Iam going wrong here.
Well, if you want signals, you know where to find them. Try
pthread_kill(). But note that it is really hard to mix signals and
threads correctly and usefully.