Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Multi-threading issues

Author: Robert Hyatt

Date: 14:37:32 11/07/02

Go up one level in this thread


On November 07, 2002 at 17:10:12, Russell Reagan wrote:

>I would like to add multi-threading into my engine, to make it interface more
>easily with winboard, and eventually play around with supporting SMP. I have a
>few questions about multi-threading issues however.
>
>I would like to be portable, but that seems rather difficult. I asked about
>pthreads, and someone said they aren't really that portable, and recommended
>using SDL (www.libsdl.org). What is the best bet if I eventually want to support
>linux/unix in addition to windows?

Pthreads is the way to go.  That is available on every unix implementation I am
aware
of.

There is nothing you can do about windows, except use the windows thread API.
However,
once you add that, you should be set for any sort of platform you run into...


>
>Secondly, I like the Interlocked functions on Windows. Is there anything similar
>on Linux or Unix?

Not sure what that is, can you explain???


>
>Lastly, is there any way to write your own routines to make your threads work
>correctly? Or is it something that has to be implemented at the OS level? What's
>wrong with passing messages between threads using simple atomic operations? For
>example, if I have an input thread, and I want to signal my search thread that
>it should stop, why can't I set a global variable that the search thread reads
>from? It seems like it would work if you did message passing using one way
>variables (like thread1 only writes to var1 and thread2 only reads var1, thread2
>only writes to var2, thread1 reads var2, etc.). In Crafty there looks like some
>code that isn't OS specific, but I don't see how it avoids synchronization
>problems.


There is no problem with that.  In fact, that (global values) is the common way
to
communicate between threads.  Note that this is an SMP-implementation since it
depends on shared memory.

In crafty, all inter-process communication is via shared memory structures...





>
>Multi-threading makes me feel quite insecure that my program is running
>bug-free. It seems like you have to be an expert on the subject before you can
>even begin to spot potential bugs. I guess it's best to stick to as few shared
>variables as possible?


It is not for the faint at heart.  The bugs you will introduce are not easily
found
using traditional debugging methods, so you are going to have to learn how to
do things by experience, which can be a very cruel teacher.

Feel free to ask however, as several of us are highly familiar with threads and
parallel programming issues...





>
>In summary, I'm lost...
>
>Russell



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.