Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Listening to I/O using a separate thread?

Author: Russell Reagan

Date: 19:02:08 02/04/03

Go up one level in this thread


On February 04, 2003 at 21:15:48, Steve Maughan wrote:

>I'm considering re-writing Monarch in 'C' (currently Delphi). One quick question
>I have is - do you need a separate thread to 'listen' for commands when writing
>a 'C' winboard program?

You do not need a seperate thread, but it is probably the cleanest way to handle
it. But, we're not writing commercial software here, so hackish things are
acceptable.

>I'm not too familar with 'C' (another reason to convert is to learn C) - but
>looking at TSCP I cannot see a separate thread - the same is true for Sjeng.
>Monarch uses a separate thread so I assumed that I would need one - now I'm
>thinking maybe I don't. Can someone clarify this? How can the engine read the
>i/o when it is pondering if there isn't another thread?

During the search you have to do a "checkup" periodically to see if there is any
input. I believe the function in TSCP is "checkup()". There is a line in the
search() function that goes something like, "if (nodes & 1023) checkup();". That
will call the function checkup() every 1024 nodes. In the checkup() function you
could check to see if there is any input from the user (or winboard), and if so,
process it, stop your search, or whatever you need to do.

>Also has anyone any pointers to information about creating a separate thread in
>C and reading the StdIO info - hopefully in a readable / understandable format.

If you are using Windows (and only windows), _beginthreadex() is the function
you should use. It is console safe, whereas CreateThread() and the other thread
creation functions are not IIRC. If you are planning on ever compiling your
engine on another operating system, use a portable threads library, such as
pthreads (posix threads).

Also, you might find this webpage helpful:
http://www.tim-mann.org/xboard/engine-intf.html#6

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.