Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Multi-threading issues

Author: Robert Hyatt

Date: 16:49:31 11/07/02

Go up one level in this thread


On November 07, 2002 at 18:05:35, Russell Reagan wrote:

>On November 07, 2002 at 17:37:32, Robert Hyatt wrote:
>
>>>Secondly, I like the Interlocked functions on Windows. Is there anything similar
>>>on Linux or Unix?
>>
>>Not sure what that is, can you explain???
>
>InterlockedIncrement()
>InterlockedDecrement()
>InterlockedExchangePointer()
>InterlockedExchangeAdd()
>InterlockedCompareExchangePointer()

Those will prevent "hardware races" but they won't stop software races.  You
have to
be careful as you tread into this stuff...

It would appear that they are simple X86 instructions accessed via a simple proc
call.


>
>You can read about them at http://msdn.microsoft.com. Basically they perform
>simple operations atomically.
>
>>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.
>
>What are the restrictions when using this method? Do I need to restrict myself
>to one way variables? Or should I be ok if either thread is writing and reading
>to any of the shared variables?


There are no "restrictions" other than those you impose on yourself.  You have
to be
aware of potential races, a case where two or more threads try to do something
to the
same variable at the same time.  Even if you "lock it" this can cause problems
if you
are not certain about your approach.

For a beginner, the less you share, the fewer potential problems you have.  For
_anything_
you share that more than one thread can modify, you have to use some sort of
atomic lock
facility (exchange instruction works well) to set a lock before entering a
critical section that
updates such data...






>
>Thanks,
>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.