This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Attached is a patch to fix a cancellation problem with cleanup handlers for POSIX threads. Your feedback is appreciated. This bug affects POSIX threads that are configured with cleanup handlers via the pthread_cleanup_push() function. The bug is that thread cancellation is not disabled by pthread_exit() while running thread cleanup handlers. The symptoms are as follows: if a thread is cancelled with pthread_cancel() while cancellation is enabled in the thread, any (cancellable) system call issued out of its cleanup handler(s) will once again trip a cancellation point. This causes the system call to be aborted AND the pthread_exit() routine to be re-entered. Although pthread_exit() seems to deal with this okay, the net effect is that the system calls in the cleanup handlers do not execute and system resources do not get cleaned up. According to POSIX: ---POSIX When a cancellation request is acted upon, the routines in the list are invoked one by one in LIFO sequence; that is, the last routine pushed onto the list (Last In) is the first to be invoked (First Out). The thread invokes the cancellation cleanup handler with cancellation disabled until the last cancellation cleanup handler returns. When the cancellation cleanup handler for a scope is invoked, the storage for that scope remains valid. If the last cancellation cleanup handler returns, thread execution is terminated and a status of PTHREAD_CANCELED is made available to any threads joining with the target. The symbolic constant PTHREAD_CANCELED expands to a constant expression of type ( void *) whose value matches no pointer to an object in memory nor the value NULL. ---POSIX So, this fix modifies pthread_exit() to disable cancellation for the thread prior to calling its cleanup handlers. I went ahead and left cancellation disabled for the remainder of pthread_exit() for two reasons: 1) The thread is exitting anyway. 2) The key destructors might also call cancellable system calls. Your comments are appreciated. Thanks, -- Dan Jakubiec Systech Corp __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree
Attachment:
pthread_cancel.pat
Description: pthread_cancel.pat
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |