This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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]

[Bug nptl/13613] Cancellation is broken in single-threaded processes


http://sourceware.org/bugzilla/show_bug.cgi?id=13613

--- Comment #3 from Rich Felker <bugdal at aerifal dot cx> 2012-05-08 21:58:29 UTC ---
I don't have a specific usage case in mind, and I don't suspect anyone would
intentionally try to cancel the main thread in a single-threaded program
knowing it's the main thread. Where the issue is likely to matter is in code
that doesn't know it's dealing with the main thread of a single-threaded
program, e.g. in a library.

The type of application it's likely to affect is an application that does `N`
jobs in parallel by spawning `N-1` threads and using the main thread as a
worker thread. As an example, I have a parallel DNS resolver tool that does
this. If it turns out that `N` is 1, no threads get created, and the process
runs single-threaded. My DNS resolver does not have the threads using
pthread_cancel on themselves, but I could imagine moderately-contrived cases
where you might want to do this. Self-cancellation is a nice way to setup
future code to abort if it does anything that would block, while avoiding
exiting immediately. (And if you've written your program this way, you can
still call functions that are cancellation points if you temporarily block
cancellation around the call.)

In any case, glibc's behavior is non-conformant. POSIX does not make any
exceptions to the rules about how cancellation works for the special case of
single-threaded programs. (In fact the only special case I can find that POSIX
makes for single-threaded programs is that you're allowed to call
async-signal-unsafe functions after fork() in a single-threaded program.)

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]