From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,2c710271be0eb4ac,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-12-19 04:37:57 PST Path: bga.com!news.sprintlink.net!pipex!lyra.csx.cam.ac.uk!rnw From: rnw@cam-orl.co.uk (Rob Walker) Newsgroups: comp.unix.osf.osf1 Subject: pthread problem Date: 19 Dec 1994 12:37:45 GMT Organization: Olivetti Research Ltd Distribution: world Message-ID: <3d3uqp$dvk@lyra.csx.cam.ac.uk> NNTP-Posting-Host: shrimp.cam-orl.co.uk Can anyone provide an explanation (& preferably a fix) for the behaviour exhibited by the following short pthreads program. When it is compiled using: gcc -o spin spin.c -lc_r -lpthreads -lmach and run it burns up all the available CPU (according to top) but the time it uses never increases -> it is very busy in the kernel. Since both threads are blocked surely the process should be idle. In the application where this was causing a problem one thread was blocked on a mutex and the other on a 'select' call. But the behaviour was the same as shown by the code below. This happens with OSF/1 V2.0 (Rev 240) - I'd very much like to hear if it occurs on a newer release (which I don't have access to). (If there is a more appropriate newsgroup for this query then please point me at it!) Thanks Rob ---------------------------------------------------------------------------- Rob Walker | Computer Science Tripos Pt II Churchill College | e-mail: rnw1000@cam.ac.uk Cambridge. CB3 0DS | rwalker@cam-orl.co.uk Telephone 01223 69509 | http://www.cam-orl.co.uk/~rnw --- cut here --- #include /* ------------------------------------------------------------- */ pthread_mutex_t mutex; pthread_mutexattr_t mutex_attr; static void *thread_go(void *arg) { pthread_mutex_lock(&mutex); } /* ------------------------------------------------------------- */ int main() { pthread_t thread; pthread_attr_t attr; pthread_mutexattr_create(&mutex_attr); pthread_mutex_init(&mutex, mutex_attr); pthread_mutexattr_setkind_np(&mutex_attr, MUTEX_FAST_NP); pthread_mutex_lock(&mutex); pthread_create(&thread, pthread_attr_default, thread_go, NULL); pthread_mutex_lock(&mutex); } --- end here ---