Click to See Complete Forum and Search --> : thread waiting at pthread_mutex_lock() does not leave the cpu


jazz123
April 27th, 2011, 12:03 AM
Hi all,

I am running a process which creates 12 threads and its function is to pass messages between other processes. Platform is montavista

The problem is :
one of its thread lock a mutex and before it can unlock it another thread try to lock that mutex and gets blocked, but for next 7 seconds no other thread get scheduled.

20 062244:538 Acquiring lock
20 062244:538 Acquired lock
20 062244:538 Message for PEER node
20 062244:676 Acquiring lock
20 062251:131 ############handleMessages: accept returned with fd:


function which was shared is
int handleMessage(void *pkt, int len)
{
int sockfd;
log("Acquiring lock");
pthread_mutex_lock(&data_handler_mutex);
log("Acquired lock");
sMessageHeader *temp = &(((sMessagePacket *)pkt)->msgHdr);
if((len != EXT_MSG_PKT_SIZE) && (len != MSG_PKT_SIZE))
log("\n ~~~~~~~ %s called for invalid length: %d",func, len); ........


please tell me what could be the problem.

MrViggy
April 27th, 2011, 12:04 PM
Isn't that what's supposed to happen? One thread locks the mutex, all others have to wait for it to unlock it.

Viggy

jazz123
April 28th, 2011, 01:40 AM
Thanks for reply,
Other threads except the one which is waiting to get lock do not use that mutex. I guess i found the problem and it is with send() which actually blocks later in that function.