Page 8 of 8

Re: how to make a chess interface

Posted: Mon Sep 03, 2012 7:08 am
by kinderchocolate
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.

Re: how to make a chess interface

Posted: Mon Sep 03, 2012 8:50 am
by hgm
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.

Re: how to make a chess interface

Posted: Mon Sep 03, 2012 5:29 pm
by UncombedCoconut
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.