This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/20619] New: pthread_cond_signal failed to wake up pthread_cond_wait


https://sourceware.org/bugzilla/show_bug.cgi?id=20619

            Bug ID: 20619
           Summary: pthread_cond_signal failed to wake up
                    pthread_cond_wait
           Product: glibc
           Version: 2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: szyhb810501.student at sina dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 9515
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9515&action=edit
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;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]