]> git.sesse.net Git - stockfish/commitdiff
Allow Bitbases::init() to be called more than once
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 Mar 2015 11:41:11 +0000 (12:41 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 23 Mar 2015 16:14:31 +0000 (17:14 +0100)
Currently if we call it more than once, we crash.

This is not a real problem, because this function is
indeed called just once. Nevertheless with this small fix,
that gets rid of a hidden 'static' variable, we cleanly
resolve the issue.

While there, fix also ThreadPool::exit to return in a
consistent state. Now all the init() functions but
UCI::init() are reentrant and can be called multiple
times.

No functional change.

src/bitbase.cpp
src/thread.cpp

index ebf3c59a02355d780e31d79b48d8e70c36ee7d6c..b3ae5c5fb5498b737ad4b0ba206268b5f3e9485d 100644 (file)
@@ -85,9 +85,10 @@ bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color us) {
 void Bitbases::init() {
 
   std::vector<KPKPosition> db(MAX_INDEX);
 void Bitbases::init() {
 
   std::vector<KPKPosition> db(MAX_INDEX);
+  unsigned id = 0;
 
   // Initialize db with known win / draw positions
 
   // Initialize db with known win / draw positions
-  std::generate(db.begin(), db.end(), [](){ static unsigned id; return KPKPosition(id++); });
+  std::generate(db.begin(), db.end(), [&id](){ return KPKPosition(id++); });
 
   // Iterate through the positions until none of the unknown positions can be
   // changed to either wins or draws (15 cycles needed).
 
   // Iterate through the positions until none of the unknown positions can be
   // changed to either wins or draws (15 cycles needed).
index ef5ae857e30580822b5c05cf2406a413a6eb05f6..048f2a7a053bcbb6cf29110498cd2f339622def7 100644 (file)
@@ -299,9 +299,12 @@ void ThreadPool::init() {
 void ThreadPool::exit() {
 
   delete_thread(timer); // As first because check_time() accesses threads data
 void ThreadPool::exit() {
 
   delete_thread(timer); // As first because check_time() accesses threads data
+  timer = nullptr;
 
   for (Thread* th : *this)
       delete_thread(th);
 
   for (Thread* th : *this)
       delete_thread(th);
+
+  clear(); // Get rid of stale pointers
 }
 
 
 }