]> git.sesse.net Git - stockfish/commitdiff
Workaround value-initialization in MSVC
authorMarco Costalba <mcostalba@gmail.com>
Fri, 8 Feb 2013 07:49:36 +0000 (08:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 8 Feb 2013 08:20:40 +0000 (09:20 +0100)
The syntax splitPoints() should force the compiler to
value-initialize the array and because there is no
user defined c'tor it falls back on zero-initialization.

Unfortunatly this is broken in MSVC compilers, because
value initialization for non-POD types is not supported,
so left splitPoints un-initialized and add in split()
initialization of slavesPositions, that is the only
member not already set at split time.

This fixes an assert under MSVC when running with
more than one thread.

Spotted and reported by Jundery.

No functional change.

src/thread.cpp

index 3b59a05df3e0711c7a2943c4d66ca254ca3e29f3..80765cdeba0a981e2bbe21120e1694f355c5040c 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <algorithm> // For std::count
 #include <cassert>
+#include <cstring> // For memset
 #include <iostream>
 
 #include "movegen.h"
@@ -43,7 +44,7 @@ namespace { extern "C" {
 // Thread c'tor starts a newly-created thread of execution that will call
 // the the virtual function idle_loop(), going immediately to sleep.
 
-Thread::Thread() : splitPoints() {
+Thread::Thread() /* : splitPoints() */ { // Value-initialization bug in MSVC
 
   searching = exit = false;
   maxPly = splitPointsSize = 0;
@@ -280,6 +281,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
   sp.cutoff = false;
   sp.ss = ss;
 
+  memset(sp.slavesPositions, 0, sizeof(sp.slavesPositions));
+
   // Try to allocate available threads and ask them to start searching setting
   // 'searching' flag. This must be done under lock protection to avoid concurrent
   // allocation of the same slave by another master.