PERFORCE change 69095 for review

David Xu davidxu at FreeBSD.org
Sat Jan 15 16:56:52 PST 2005


http://perforce.freebsd.org/chv.cgi?CH=69095

Change 69095 by davidxu at davidxu_tiger on 2005/01/16 00:56:47

	Make pthread_cancel async cancellation safe.

Affected files ...

.. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_cancel.c#7 edit

Differences ...

==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_cancel.c#7 (text+ko) ====

@@ -35,15 +35,25 @@
 __weak_reference(_pthread_setcanceltype, pthread_setcanceltype);
 __weak_reference(_pthread_testcancel, pthread_testcancel);
 
+int _pthread_setcanceltype(int type, int *oldtype);
+
 int
 _pthread_cancel(pthread_t pthread)
 {
 	struct pthread *curthread = _get_curthread();
 	int oldval, newval = 0;
+	int oldtype;
 	int ret;
 
-	if ((ret = _thr_ref_add(curthread, pthread, 0)) != 0)
+	/*
+	 * POSIX says _pthread_cancel should be async cancellation safe,
+	 * so we temporarily disable async cancellation.
+	 */
+	_pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
+	if ((ret = _thr_ref_add(curthread, pthread, 0)) != 0) {
+		_pthread_setcanceltype(oldtype, NULL);
 		return (ret);
+	}
 
 	do {
 		oldval = pthread->cancelflags;
@@ -56,6 +66,7 @@
 		thr_kill(pthread->tid, SIGCANCEL);
 
 	_thr_ref_delete(curthread, pthread);
+	_pthread_setcanceltype(oldtype, NULL);
 	return (0);
 }
 


More information about the p4-projects mailing list