Dealock issues related to mutex and thread termination.
Dealock issues related to mutex and thread termination.
- Subject: Dealock issues related to mutex and thread termination.
- From: Stéphane Letz <email@hidden>
- Date: Fri, 30 May 2008 10:32:56 +0200
Hi,
We have a thread that locks a mutex and terminates, either itself or
being "killed" by another thread. If this thread is "cancellable"
using the phread API pthread_cancel()/pthread_join(), then we can
possibly use pthread_cleanup_push/pthread_cleanup_pop at the
appropriate place to properly unlock the mutex at termination stage.
This seems to work correctly.
But in some cases the thread is waiting on a low-level mach semaphore
(we are directly using semaphore_wait/semaphore_signal kind of API)
and the thread cannot be cancelled using pthread_cancel()/
pthread_join(). Thus we use the following kind of code to terminate
the thread:
mach_port_t machThread = pthread_mach_thread_np(fThread);
thread_terminate(machThread);
but then is seems that the pthread_cleanup_push/pthread_cleanup_pop
method to unlock the mutex does not work anymore.... and we have a
deadlock later on.
So:
1) Is there a way to cancel a thread waiting using semaphore_wait
using standard pthread API? So that thread_cleanup_push/
pthread_cleanup_pop can be used?
2) Is case 1) is no, is there any other method to add cleanup handlers
when using low-level thread_terminate API?
Thanks
Stephane Letz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden