Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* pthread problem
@ 1994-12-19 12:37 Rob Walker
  1994-12-20 23:14 ` Jeffrey M. Denham
  0 siblings, 1 reply; 2+ messages in thread
From: Rob Walker @ 1994-12-19 12:37 UTC (permalink / raw)



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.h>

/* ------------------------------------------------------------- */
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 ---




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1994-12-20 23:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-12-19 12:37 pthread problem Rob Walker
1994-12-20 23:14 ` Jeffrey M. Denham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox