Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: And now something completely different: Multithreading

Author: Robert Hyatt

Date: 07:46:00 12/01/03

Go up one level in this thread


On December 01, 2003 at 02:41:28, Tony Werten wrote:

>When my masterthread is spinning, waiting for results from it's workers threads,
>how do I keep it from burning CPU time ?

You have a couple of choices.  But why is it important?  You have two cpus.  One
thread is doing something useful, the other is spinning.  What is the problem?
The spinning thread has _zero_ effect on the running thread.  IE in crafty I
have something like this:

while (!work);

work gets copied into cache.  Until another thread writes to it, I spin on
local cache, no bus traffic whatsoever, and the instant I get work I start
to work on it the very next CPU cycle.  If you block, you take a huge
performance hit to block and then unblock.

>
>The apifunction sleep() doesn't some threadsafe, suspending the thread and
>having it resumed by the worker seems overly complicated. ( Accept maybe if I
>can use a callback function )
>

use a mutex-type lock that blocks when the lock is already set.  Or if
using posix threads a "condition variable" will work better as multiple
threads can wait for the condition to be satisfied and all can proceed
when it is.  But spinning is _the_ high-performance solution.

IE I certainly hope you use spinlocks rather than blocking locks for
mutual exclusion/critical sections???


>Any thoughts ?
>
>Tony



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.