Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Need a little help with multithreaded programming

Author: Dan Newman

Date: 23:42:20 12/27/01

Go up one level in this thread


On December 27, 2001 at 21:52:57, Dann Corbit wrote:

>On December 27, 2001 at 21:26:01, Russell Reagan wrote:
>
>>I've taken a look at the Interlocked functions and they look like the best
>>solution since I'll be mainly dealing with some simple data shared between
>>threads. I'd like to make sure I'm understanding a few of them. With pointers
>>aside...
>>
>>InterlockedExchange(A,B) is equivalent to A = B
>>
>>InterlockedCompareExchange(A,B,C) is equivalent to if(A == C) A = B;
>>
>>InterlockedDecrement(A) is equivalent to A--;
>>
>>InterlockedIncrement(A) is equivalent to A++;
>>
>>InterlockedExchangeAdd(A,B) is equivalent to A = A + B;
>>
>>Are these statments *basically* correct? Of course I have left out the facts
>>that some parameters are pointers and such, but I'm working on getting the
>>"general idea" here :)
>>
>>If I am correct in my understanding of how these functions work, then I thank
>>you all very much for your help.
>
>That's the basic notion.  I would encourage you to go over your data structures
>and carefully see which ones can be made automatic and which ones need to be
>public.  I think Dr. Hyatt has figured out some way to access the hash table
>from multiple threads without any locking at all (though for the life of me, I
>can't see how this is possible).  So you might want to go over his hash table
>stuff.

It's a really neat trick.  I think Tim Mann came up with it.  The idea is
that you take the data (score, move, etc.) being stored in the hash table
entry and hash it (XOR it) into the position's hash code and store that
instead of the actual hash code.  Then when you retrieve the entry you copy
it into local memory (so it won't change while you're fooling with it) and
XOR the data into the stored "hash code" to retrieve the actual position
hash code.

Now, if anything in the entry has been trashed by having multiple threads
write to it simultaneously or by being read while it was being written to,
then the position hash code that you've recovered from the entry will also
be corrupted and likely won't match the current position's hash code, so
you don't get a hit.

-Dan.

>
>Also, think about portability.  If possible, isolate your system specific stuff
>so that when you port to another platform, it won't be horribly painful.



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.