Bug 20619 - pthread_cond_signal failed to wake up pthread_cond_wait
Summary: pthread_cond_signal failed to wake up pthread_cond_wait
Status: RESOLVED WORKSFORME
Alias: None
Product: glibc
Classification: Unclassified
Component: nptl (show other bugs)
Version: 2.9
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-19 08:19 UTC by szyhb810501.student
Modified: 2016-10-04 10:02 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
the program (752 bytes, text/x-csrc)
2016-09-19 08:19 UTC, szyhb810501.student
Details

Note You need to log in before you can comment on or make changes to this bug.
Description szyhb810501.student 2016-09-19 08:19:14 UTC
Created attachment 9515 [details]
the program

Run the program as follows on ARM CPU for several minutes, and pthread_cond_signal failed to wake up pthread_cond_wait. Run the command "cat /data/pthread_cond_wait.txt", you will find that before_wait and after_wait stop incrementing. The version of glibc is 2.4, and the version of Linux kernel is 3.10.18.
  Run the program on MIPS CPU for one hour, the problem does not occur.

#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/stat.h>


static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;


static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;


/* 苹果的数量 */
static int apples;


/* 生产苹果的线程 */
static void *thread_fn(void *arg)
{
    prctl(PR_SET_NAME, "test_sender");


    while(1) {
        pthread_mutex_lock(&mutex);
        if (apples < 256) {
            apples++;
        }
        pthread_mutex_unlock(&mutex);


        pthread_cond_signal(&cond);
        //pthread_cond_broadcast(&cond);
    }


    return NULL;
}


int main(void)
{
    int ret;
    pthread_t thread;
    unsigned int before_wait, after_wait;
    int fd;


    prctl(PR_SET_NAME, "test_recver");
    fd = open("/data/pthread_cond_t.txt",
        O_RDWR | O_CREAT | O_TRUNC,
        S_IRWXU | S_IRWXG | S_IRWXO);
    if (fd >= 0) {
        char buf[100];


        snprintf(buf, sizeof(buf), "&cond.__data.__futex=%p.\n",
            &cond.__data.__futex);
        write(fd, buf, strlen(buf));
        close(fd);
    }
            
    ret = pthread_create(&thread, NULL, thread_fn, NULL);
    if (ret != 0) {
        return EXIT_FAILURE;
    }


    before_wait = after_wait = 0;
    /* 消费苹果 */
    while(1) {
        pthread_mutex_lock(&mutex);
        while(apples == 0) {
            before_wait++;
            fd = open("/data/pthread_cond_wait.txt",
                O_RDWR | O_CREAT | O_TRUNC,
                S_IRWXU | S_IRWXG | S_IRWXO);
            if (fd >= 0) {
                char buf[100];


                snprintf(buf, sizeof(buf), " before_wait=%u, after_wait=%u.\n",
                    before_wait, after_wait);
                write(fd, buf, strlen(buf));
                close(fd);
            }


            pthread_cond_wait(&cond, &mutex);


            after_wait++;
            fd = open("/data/pthread_cond_wait.txt",
                O_RDWR | O_CREAT | O_TRUNC,
                S_IRWXU | S_IRWXG | S_IRWXO);
            if (fd >= 0) {
                char buf[100];


                snprintf(buf, sizeof(buf), " before_wait=%u, after_wait=%u.\n",
                    before_wait, after_wait);
                write(fd, buf, strlen(buf));
                close(fd);
            }
        }
        apples--;
        pthread_mutex_unlock(&mutex);
    }


    return 0;
}
Comment 1 Florian Weimer 2016-09-19 08:56:19 UTC
Can you reproduce this with a newer glibc version than 2.4?  2.4 is really old.
Comment 2 szyhb810501.student 2016-09-20 03:21:25 UTC
Sorry, I made a mistake.The version of glibc is 2.9.
Comment 3 Florian Weimer 2016-09-20 05:11:24 UTC
Same question still applies; glibc 2.9 is only marginally newer.
Comment 4 szyhb810501.student 2016-09-30 07:55:54 UTC
I have no newer glibc.
Can you provide me with cross compile toolchain?
OS: Ubuntu 10.04
Host CPU: i386
Target CPU: ARM cortex-A9
Comment 5 Florian Weimer 2016-10-04 10:02:28 UTC
Sorry, you need to talk to those who provided you with your development environment.  It is rather outdated by this point, and the general ARM toolchain has too many unknowns/configurable parts.