Thanks for all your help. It was as Jef suggested, due to not using the pthread_mutex_destory() function correctly. Once I had them at the right places, it is working fine.