Mutex lock question

Hi all,
I have a scenario where I need to use the mutex locks. The mutex locks are working fine, but sometimes I am getting into the dead lock situation.

Below is the summary of my code :

MUTEX LOCK
performTask();
MUTEX UNLOCK.

In some cases I get into the situation where the thread is hung at performTask() function and never returns. When this happens the other threads which are waiting are blocked.

Please let me how can I kill the thread which is hung at performTask() function. Apart from using timed Mutex, is there a way I can return from performTask() function after waiting for a specified time?.

THanks
Joy

Look up pthread_cancel(), pthread_setcancelstate(), pthread_cleanup_push(), and pthread_cleanup_pop().

And be aware that canceling threads is playing with fire. You may cause worse problems than you are trying to solve.

You can cancel a thread from the outside with pthread_cancel if the thread has allowed cancellation with pthread_setcancelstate. Even if only set to queue cancellations, Your thread could still check if its been cancelled occasionally. If its state still allows it to check that is.