Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Separate Thread or plain Loop??

Author: Miguel A. Ballicora

Date: 09:32:43 12/18/01

Go up one level in this thread


On December 18, 2001 at 11:21:17, David Rasmussen wrote:

>On December 18, 2001 at 07:27:47, Steve Maughan wrote:
>
>>I'm thinking about implementing pondering in my chess progam.  I guess I have
>>two options - either create a separate thread for the engine or use some form of
>>loop that checks for input and responds accordingly.  The latter seems like a
>>pseudo thread and may take up significant processor time.  I have never written
>>a program that creates separate threads and I guess that if I do go down that
>>route I'll have to deal with syncronization and other unknown complications.
>>
>>Do others create separate threads?  Are there any advantages / disadvantages
>>with creating a separate thread for the search?  What effect will it have on the
>>speed?  Will it mean that in the long-run it will be able to interface more
>>smoothly with the GUI?  Are there any simple solutions?
>>
>>All help appreciated!
>>
>>Regards,
>>
>>Steve
>
>Non-threaded:
>Pro: You will not have to deal with threading. That means you won't have to find
>a semi-portable way of doing threading, and also, you wont have to learn
>anything about the subtleties of concurrent programming (mutual exclusion,
>races, etc.)
>Con: The design will be messier, potentially a lot messier, if you aren't
>careful.
>
>Threaded: (conversely)
>Pro: The design will be very elegant and simple once you have your primitives
>working.
>Con: You'll have to learn a (very) little bit about concurrent programming, and
>you'll have to choose a threading library that works on your favorite platforms,
>since there is not portable way of threading in, say, C or C++.

Well, there is not portable way to poll in C either. So, if portability is an
issue, the question is which approach will give "better chances" to port it.
I do not think that doing it with threads is necessarily more difficult to port.
It depends very much on how it was implemented, I guess. The way I did it
I used only two functions that I should be able to find in any multithreaded
environment. One that launches the thread and another that waits to finish (so
one thread can wait to the other after sending a message (a global variable)
that a move has been entered etc.)
I am NOT an expert on this, but I guess that I should be able to port this
without much of a headache. I have't tried yet.

Regards,
Miguel


>I thought it was an exciting task to make as good a non-threaded design as
>possible, so I did it non-threaded. But if you're starting from scratch, you
>might as well go for a threaded version. It can be difficult and error-prone to
>do it non-threaded, and once you've learned a little bit about threading (which
>is always a good thing, learning is), you have the benefit of a clean design and
>also, you are ready to make your search multithreaded as well (not as simple,
>but you'll still have to learn the basics for that anyway).
>
>/David



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.