how to make a chess interface

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
kinderchocolate
Posts: 411
Joined: Mon Nov 01, 2010 5:55 am
Full name: Ted Wong
Contact:

Re: how to make a chess interface

Post by kinderchocolate » Mon Sep 03, 2012 5:08 am

lucasart wrote:
Another thing I will need is to block/unblock processes. Do you know how to do that (in POSIX) ? When I play A vs. B, if it's A's turn to play, I want to block B, let A calculate, and when it's B's turn I unblock it. The point is that B could be in a polling loop: if B uses blocking I/O (which is the correct way and I suppose any normal engine does that) then there's no real issue, but if it uses a loop with non blocking I/O it steals CPU ressources from A. Also I want to disable pondering in a forceful way, so as to control it.
Well, you'll make yourself more troubles very soon. I strongly recommend you don't try to attempt it. Because you will need to rework the whole thing very soon....

Anyway, you're talking about synchronization. There're many ways. You might try to use asynchronous messages.

Send a "STOP" message from A to B, when B reads it, immediately block itself. So on...

In any decent GUI, there must be a thread for block polling. I strongly recommend you go straight into creating threads for polling. If you're in doubt, please read Polyglot, it has a very nice implementation.

User avatar
hgm
Posts: 23718
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: how to make a chess interface

Post by hgm » Mon Sep 03, 2012 6:50 am

I never looked at how Polyglot does this, but in UCI2WB I use a pipe for hread synchronization. The advantage is that I don't have to worry about race conditions: unlocking is done by writing a byte in the pipe, and it can be done even before the thread to be unlocked reaches the blocking read call for the pipe. Becaue in that case it will find data in the pipe, and the read call will not block at all.

UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 10:40 am
Location: Naperville, IL

Re: how to make a chess interface

Post by UncombedCoconut » Mon Sep 03, 2012 3:29 pm

lucasart wrote:Another thing I will need is to block/unblock processes. Do you know how to do that (in POSIX) ? When I play A vs. B, if it's A's turn to play, I want to block B, let A calculate, and when it's B's turn I unblock it. The point is that B could be in a polling loop: if B uses blocking I/O (which is the correct way and I suppose any normal engine does that) then there's no real issue, but if it uses a loop with non blocking I/O it steals CPU ressources from A. Also I want to disable pondering in a forceful way, so as to control it.
kill(pid_B, SIGSTOP) and later kill(pid_B, SIGCONT)?
This isn't foolproof (e.g. if process B is wb2uci and the actual engine is *its* child process). I'm not sure if there is a portable way that's foolproof.

Post Reply