pthread_cond_timedwait hang when hibernate and wake up

Bug #806844 reported by dqiyy
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

we use pthread_cond_timedwait in our thread programing , but when the thread functon is call ing pthread_cond_timedwait and during the wait(not time out), and at that time system go to hibernate when the system wake up ,the function call is never returned or stopped waiting, the timeout limitation is also not work.
we tested on Ubunto 10.10 and this not happen, but on 11.04 (kernel version )this is happend every time

Revision history for this message
Daniel Manrique (roadmr) wrote :

Hello,

Thank you for taking the time to report this bug and helping to make Ubuntu better.

If the issue didn't occur with Ubuntu 10.10, it might be kernel-related. You could try the following to install the 10.10 kernel, and test if the behavior improves.

For this, you should create a file /etc/apt/sources.list.d/maverick.list containing these two lines:

deb http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted

(you might want to substitute "us" for the identifier of a mirror closer to you).

Then run these commands:

sudo apt-get update
sudo apt-get install linux-image-2.6.35-28-generic

When your system is booting, press the left shift key to get the grub menu and select the kernel you want to boot.

If it turns out to be a kernel issue, please let me know, so I can give you some instructions on how to collect relevant debugging information that will help pinpoint the problem.

It would also be really helpful if you could provide us with a minimal program that showcases the behavior, such that a developer can compile it and run local tests to try and replicate the behavior you observe.

Please let me know about the results of the tests I suggest so we can move this bug report forward.

Thanks for your help!

Changed in ubuntu:
status: New → Incomplete
Revision history for this message
dqiyy (duanqian) wrote :

Thank you for your reply so much. I'm afraid that My ubuntu can not connect to the internet .
but as our test I guess it is relaeted to the kerne change, we tested the latest release for OpenSuse Release version , Also this problem happend.

Some Demo Code

 pthread_mutex_lock(&mut);
 gettimeofday(&nwtm, NULL);
 sync_timer.tv_sec = nwtm.tv_sec + timeout;
 sync_timer.tv_nsec = nwtm.tv_usec * 1000;
 syslog(LOG_ERR, "sync_wait: pthread_cond_timedwait entry.\n");
 int retcode = pthread_cond_timedwait(&cond, &mut, &sync_timer);
 syslog(LOG_ERR, "sync_wait: pthread_cond_timedwait end.\n");
 pthread_mutex_unlock(&mut);

just after calling pthread_cond_timedwait, then Hibernate the System, After some time , Wake it up. but the function call is never returned or reponse

Revision history for this message
Daniel Manrique (roadmr) wrote :

Hello,

Thanks for getting back to me.

If your Ubuntu machine has no Internet connectivity, you could run apport-bug to collect the required information and save it to a file. This information is important and required so we can :

apport-bug --save /tmp/pthread.apport linux

Then, copy that to a machine that has Internet access and run:

apport-bug pthread.apport

This will probably create a new bug report, if so, that's fine, we'll mark this one as a duplicate.

Also, the code you showed me is fine, but I see it lacks variable declarations, a main() function and header files. Since you probably know more about pthread programming than me, I'd really appreciate if you could attach to this bug report a .c file I could compile to run the test, since I don't really know how to turn your code into a fully working program.

Thanks for all your help!

---
Ubuntu Bug Squad volunteer triager
http://wiki.ubuntu.com/BugSquad

Revision history for this message
dqiyy (duanqian) wrote :

I have a try to apport-bug, but it is not working on my ubunto
here is the full test code

#include <stdio.h>
#include <errno.h>
#include <pthread.h>
#include <sys/time.h>
#include <syslog.h>

pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

int sync_wait(int timeout)
{
    struct timeval nwtm;
    struct timespec sync_timer;
    int retcode = 0;

    pthread_mutex_lock(&mut);
    gettimeofday(&nwtm, NULL);
    sync_timer.tv_sec = nwtm.tv_sec + timeout;
    sync_timer.tv_nsec = nwtm.tv_usec * 1000;
    retcode = pthread_cond_timedwait(&cond, &mut, &sync_timer); //在ubuntu10.10下睡眠唤醒后能继续执行,但在ubuntu11.04下不行
    pthread_mutex_unlock(&mut);

    return retcode;
}

int sync_notify()
{
    int retcode;
    pthread_mutex_lock(&mut);
    retcode = pthread_cond_signal(&cond);
    pthread_mutex_unlock(&mut);
    return retcode;
}

int main(int argc, char *argv[])
{
    int icount = 0;
    sync_notify();

    while (1)
    {
        if (ETIMEDOUT == sync_wait(50))
        {
            syslog(LOG_ERR, "sync_wait is timeout.\n");
        }

        icount++;
        if (10 < icount)
        {
            break;
        }
    }

    return 1;
}

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Ubuntu because there has been no activity for 60 days.]

Changed in ubuntu:
status: Incomplete → Expired
affects: ubuntu → linux (Ubuntu)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.