[PATCH][BZ #13613] Allow a single-threaded process to cancel itself

Siddhesh Poyarekar siddhesh@redhat.com
Wed May 9 14:54:00 GMT 2012


Hi,

A single-threaded process cannot cancel itself using pthread_cancel()
as reported in the bz. This is because header.multiple_threads is not
set till a thread is cloned and cancellation point entries are guarded
by this.

This is a little odd in terms of a request since this can be easily
done for the main process using exit and atexit. However, there is
nothing in the specification of pthread_cancel that explicitly
disallows this, so for the sake of compliance, pthread_cancel should
work for a single-threaded process too.

Attached patch unconditionally enables multiple_threads in the caller
of pthread_cancel. This should have an impact only for a
single-threaded process since any threads in a multi-threaded process
should have that flag enabled. This was suggested in the bz by Jakub
Jelinek. I have also added a test case to verify that this is fixed.

I have run this on x86_64 with the test case with and without the
patch to make sure that this is fixed. I did not find any regressions
introduced as a result of this patch.

Regards,
Siddhesh

nptl/ChangeLog:

2012-05-09  Siddhesh Poyarekar  <siddhesh@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	[BZ #13613]
	* nptl/pthread_cancel.c (pthread_cancel): Enable
	multiple_threads before marking the thread as cancelled.
	* nptl/tst-cancel-self.c: New test case.
	* nptl/Makefile (tests): Add tst-cancel-self.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pthread-cancel-self.patch
Type: text/x-patch
Size: 2942 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120509/d8bfda1e/attachment.bin>


More information about the Libc-alpha mailing list