Re: Problem with pthread_con
"dada1" <[email protected]> Fri, 12 Sep 2003 10:08:36 +0200
| Newsgroups | gmane.comp.lib.phil |
|---|---|
| Message-ID | <003801c37905$118397e0$890010ac@edumazet> |
Just got it now : In fact the 3 threads looks to be stuck on the pthread_mutex 'U.lock' , not the cond.lock pid 1234 is the pid of the the 'main' thread, pid 1235 and 1236 pids of the workers threads 0x809ac0 is the address of U.lock # strace -p 1234 Process 1234 attached - interrupt to quit futex(0x809ac0, FUTEX_WAIT, 8, NULL <unfinished ...> Process 1234 detached # strace -p 1234 Process 1234 attached - interrupt to quit futex(0x809ac0, FUTEX_WAIT, 12, NULL <unfinished ...> Process 1234 detached # strace -p 1235 Process 1235 attached - interrupt to quit futex(0x809ac0, FUTEX_WAIT, 16, NULL <unfinished ...> Process 1235 detached # strace -p 1236 Process 1236 attached - interrupt to quit futex(0x809ac0, FUTEX_WAKE, 1) = 1 futex(0x809ad8, FUTEX_WAKE, 1) = 1 futex(0x809ae8, FUTEX_WAIT, 12322, NULL) = -1 EAGAIN (Resource temporarily unavailable) futex(0x809ac0, FUTEX_WAIT, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable) futex(0x809ac0, FUTEX_WAIT, 5, NULL) = 0 futex(0x809ac0, FUTEX_WAKE, 1) = 0 futex(0x809ae8, FUTEX_WAIT, 12323, NULL) = 0 futex(0x809ac0, FUTEX_WAKE, 1) = 0 ... All threads are running now. Next time it reblocks, I will use 'strace -p 1236' directly Thanks From: "dada1" <[email protected]> > Hello Ulrich > > I have a problem with pthread_cond_signal() (nptl 0.58) > > A very simple program can block. It is very rare. > > I dont know yet if this is a kernel bug, a processor bug, or a bug from me ! > > Usually, doing a strace -p one_pid unblocks the program. > (the threads seems blocked to get the condvar.lock) > > Tested on a bi athlon, kernel 2.6.0-test5 > > Thanks > Eric Dumazet > > Sample program (without error checks for clarification) : > > #include <pthread.h> > > #define MAXWORK 8 > > struct { > pthread_mutex_t lock ; > pthread_cond_t cond ; > unsigned int unload ; > unsigned int load ; > unsigned long miss ; > struct { > int delai ; > } tab[MAXWORK] ; > } U ; > > > void *worker(void *arg) > { > int delai ; > > for (;;) { > > pthread_mutex_lock(&U.lock) ; > while (U.load == U.unload) { > pthread_cond_wait(&U.cond, &U.lock) ; > } > delai = U.tab[U.unload%MAXWORK].delai ; > U.unload++ ; > pthread_mutex_unlock(&U.lock) ; > > usleep(delai) ; /* some work */ > } > > } > > void post_work() > { > int delai = rand() % 50000 ; > unsigned int nb ; > pthread_mutex_lock(&U.lock) ; > nb = U.load - U.unload ; > if (nb < MAXWORK) { > U.tab[U.load%MAXWORK].delai = delai ; > U.load++ ; > pthread_mutex_unlock(&U.lock) ;/* so that awaken thread doesnt have > to wait for the lock */ > pthread_cond_signal(&U.cond) ; > } > else { > U.miss++ ; > pthread_mutex_unlock(&U.lock) ; > } > } > > > int main(int argc, char *argv[]) > { > time_t t0 , t1 ; > pthread_t tid1 ; > pthread_t tid2 ; > > pthread_create(&tid1, 0, worker, 0) ; > pthread_create(&tid2, 0, worker, 0) ; > > t0 = time(0) ; > for (;;) { > post_work() ; > usleep(rand() % 50000) ; > t1 = time(0) ; > if (t1 != t0) { > t0 = t1 ; > write(1, "*", 1) ; > } > } > } > > > -- > Phil-list mailing list > [email protected] > https://www.redhat.com/mailman/listinfo/phil-list >