From: rnw@cam-orl.co.uk (Rob Walker)
Subject: pthread problem
Date: 19 Dec 1994 12:37:45 GMT [thread overview]
Message-ID: <3d3uqp$dvk@lyra.csx.cam.ac.uk> (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 ---
next reply other threads:[~1994-12-19 12:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-12-19 12:37 Rob Walker [this message]
1994-12-20 23:14 ` pthread problem Jeffrey M. Denham
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox