svn commit: r214826 - user/davidxu/libthr/lib/libthr/thread
David Xu
davidxu at FreeBSD.org
Fri Nov 5 07:03:36 UTC 2010
Author: davidxu
Date: Fri Nov 5 07:03:35 2010
New Revision: 214826
URL: http://svn.freebsd.org/changeset/base/214826
Log:
Don't forget to lock the mutex again before doing thread cancellation.
Modified:
user/davidxu/libthr/lib/libthr/thread/thr_cond.c
Modified: user/davidxu/libthr/lib/libthr/thread/thr_cond.c
==============================================================================
--- user/davidxu/libthr/lib/libthr/thread/thr_cond.c Fri Nov 5 06:42:30 2010 (r214825)
+++ user/davidxu/libthr/lib/libthr/thread/thr_cond.c Fri Nov 5 07:03:35 2010 (r214826)
@@ -259,6 +259,7 @@ cond_wait_user(pthread_cond_t *cond, pth
} else if (cancel && SHOULD_CANCEL(curthread) &&
!THR_IN_CRITICAL(curthread)) {
_thr_umtx_unlock(&cv->c_lock);
+ _mutex_cv_lock(mutex, recurse);
_pthread_exit(PTHREAD_CANCELED);
}
}
@@ -292,7 +293,15 @@ cond_wait_common(pthread_cond_t *cond, p
(cv->c_kerncv.c_flags & USYNC_PROCESS_SHARED))
return (EINVAL);
+ /*
+ * If the thread is real-time thread or if it holds priority mutex,
+ * it should use kernel based cv, because the cv internal lock
+ * does not protect priority, it can cause priority inversion.
+ * Note that if it is robust type of mutex, we should not use
+ * the internal lock too, because it is not robust.
+ */
if (curthread->attr.sched_policy != SCHED_OTHER ||
+ curthread->priority_mutex_count != 0 ||
(m->m_lock.m_flags & (UMUTEX_PRIO_PROTECT|UMUTEX_PRIO_INHERIT)) != 0)
return cond_wait_kernel(cond, mutex, abstime, cancel);
else
More information about the svn-src-user
mailing list