[691] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: CPU hog?

daemon@ATHENA.MIT.EDU (Thierry Baron)
Mon Jul 28 10:36:46 1997

Date: Mon, 28 Jul 1997 10:07:55 -0400
From: Thierry Baron <baron@cim.mcgill.ca>
To: "Andrew N. Edmond" <edmond@shaman.lycaeum.org>
Cc: pthreads@MIT.EDU

Andrew N. Edmond wrote:
> 
> I have written a pretty simple mutlithreaded application with
> Pthreads/1.60b6.  There are two threads, one waiting for input from a
> socket, the other processing data received.
> 
> When I run this program (counterd), it's using 100% of the available CPU!
> 
> So, I made another program, just one thread, that simply listens on a
> socket, and does nothing else.  This too is using 100% of the available
> CPU!
> 
> Is there a way to eliminate this behavior?
> 
> Andy
>

you have to put a timeout (>~100ms) in the select for incoming socket
connections.
This enables to release the CPU. To enforce that, you can also add a
pthread_yield 
in your loops.

--
Thierry

home help back first fref pref prev next nref lref last post