Subj : Re: pthread_cond_timedwait() wastes CPU time To : comp.programming.threads From : Joe Seigh Date : Thu Feb 17 2005 09:25 pm On Thu, 17 Feb 2005 20:35:39 -0500, Laurent Birtz wrote: > Hi, > > I'm running into a strange problem related to pthread on Linux. > > I have a program that contacts a server regularly, and its operations > should take very little CPU. The program uses several threads, but > all are blocked save one. > [...] > > pthread_cond_timewait() is not the only place where the time is lost - > I suppose I could detect the same behavior around mutex lock calls > and such. > > The program doesn't receive signals. The thread consuming the time > mostly does read(), write() and poll() calls on a socket before > going back to sleep with pthread_cond_timedwait(). > > So what's happening in pthread_cond_timedwait()? > > > I'd appreciate any help on the issue. The problem is not critical, but > it makes my program waste 3 seconds of CPU time per hour on average. > Something is wrong and I'd like to know what it is. > Well, if it's NPTL threads, they wait on futexes. Any signals the threads receive will show up as spurious wakeups for the condition variables. The mutexes will wakeup and rewait on the futex. See what signals are occuring. If they're yours, you might be able to set the per thread signal masks so only the threads you want get the signals. If they're system signals there may not be much that you can do about it. 3 seconods per hours doesn't seem bad. I'm doing performance improvement stuff where only 5% improvement in performance doesn't seem significant. -- Joe Seigh .