CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Question thread waiting at pthread_mutex_lock() does not leave the cpu

    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.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: thread waiting at pthread_mutex_lock() does not leave the cpu

    Isn't that what's supposed to happen? One thread locks the mutex, all others have to wait for it to unlock it.

    Viggy

  3. #3
    Join Date
    Apr 2011
    Posts
    3

    Re: thread waiting at pthread_mutex_lock() does not leave the cpu

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured