]> git.sesse.net Git - stockfish/commit
Correctly handle handover of setup states
authorMarco Costalba <mcostalba@gmail.com>
Mon, 27 Aug 2012 12:39:59 +0000 (14:39 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 27 Aug 2012 17:17:02 +0000 (19:17 +0200)
commit3df2c01b5769c7ae996fb5b992c06e4a5428ad35
treeefa0e45fb70b3ca665c1610485400a0c1b449126
parent8991a6f0057ff8e9abf8989426f97753405bb301
Correctly handle handover of setup states

Before the search we setup the starting position doing all the
moves (sent by GUI) from start position to the position just
before to start searching.

To do this we use a set of StateInfo records used by each
do_move() call. These records shall be kept valid during all
the search because repetition draw detection uses them to back
track all the earlier positions keys. The problem is that, while
searching, the GUI could send another 'position' command, this
calls set_position() that clears the states! Of course a crash
follows shortly.

Before searching all the relevant parameters are copied in
start_searching() just for this reason: to fully detach data
accessed during the search from the UCI protocol handling.
So the natural solution would be to copy also the setup states.
Unfortunatly this approach does not work because StateInfo
contains a pointer to the previous record, so naively copying and
then freeing the original memory leads to a crash.

That's why we use two std::auto_ptr (one belonging to UCI and another
to Search) to safely transfer ownership of the StateInfo records to
the search, after we have setup the root position.

As a nice side-effect all the possible memory leaks are magically
sorted out for us by std::auto_ptr semantic.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/benchmark.cpp
src/search.cpp
src/search.h
src/thread.cpp
src/thread.h
src/uci.cpp