Re: pthread_cancel causing infinite memory allocation loop
- From: Måns Rullgård <mans@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 00:26:53 +0100
captain_oldfield <toldfield@xxxxxxxxxxxxxxxx> writes:
Hi,
I have a section of "cancel-unsafe" code in a thread that I am
protecting with pthread_setcancelstate(DISABLED) and
pthread_setcancelstate(ENABLED). This code is adding to a linked list
from the C++ STL.
The majority of my code is ANSI C. On occasions I have seen the thread
get stuck in the list memory allocation loop when I have attempted to
cancel it. I find this impossible to believe, as the code should not
even be receiving a cancel notifiation, due to the
pthread_setcancelstate protection. I am using deferred cancellation,
not asynchronous.
Does anyone have any ideas how this could occur?
Using pthread_cancel() is generally a very bad idea, as you have
witnessed. I have no other advice than to rewrite your code in a way
that doesn't need it.
Also, how does pthread_cancel actually work (this is in Solaris 9) -
does it use signals underneath?
Whatever it uses, you shouldn't, as an application author, need to
care about it. The exact mechanisms used will certainly vary between
implementations.
Is C++ STL compatible with the POSIX pthreads library?
I very much doubt that STL is thread-safe without additional locking
precautions, though I am not sure about this.
--
Måns Rullgård
mans@xxxxxxxxx
.
- References:
- pthread_cancel causing infinite memory allocation loop
- From: captain_oldfield
- pthread_cancel causing infinite memory allocation loop
- Prev by Date: pthread_cancel causing infinite memory allocation loop
- Next by Date: getpriority and renice
- Previous by thread: pthread_cancel causing infinite memory allocation loop
- Next by thread: Re: pthread_cancel causing infinite memory allocation loop
- Index(es):
Relevant Pages
|
|