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; }
Can you reproduce this with a newer glibc version than 2.4? 2.4 is really old.
Sorry, I made a mistake.The version of glibc is 2.9.
Same question still applies; glibc 2.9 is only marginally newer.
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
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.