]> git.sesse.net Git - stockfish/commit
Terminate threads before to exit main()
authorMarco Costalba <mcostalba@gmail.com>
Wed, 29 Aug 2012 14:43:01 +0000 (16:43 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 29 Aug 2012 17:11:44 +0000 (19:11 +0200)
commit8dcb4bc3cce1f487cfac65ed20d21378d0f39b2e
treee124bb5041c4af8d131ed3b1f34054a911ebf443
parent0a003d3ba1e3082132606d06159693aaa805a138
Terminate threads before to exit main()

It is very difficult and risky to assure
that a running thread doesn't access a global
variable. This is currently true, but could
change in the future and we don't want to rely
on code that works 'by accident'. The threads
are still running when ThreadPool destructor is
called (after main() returns) and this could
lead to crashes if a thread accesses a global
that has been already freed. The solution is to
use an exit() function and call it while we are
still in main(), ensuring global variables are
still alive at threads termination time.

No functional change.

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