mirror of
https://github.com/sockspls/badfish
synced 2025-05-17 07:59:36 +00:00
Check for thread creation successful completion
It is a good programming practice to verify a system call has indeed succeed. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
290caf9960
commit
941016e7a2
1 changed files with 21 additions and 10 deletions
|
@ -573,6 +573,7 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||||
void init_threads() {
|
void init_threads() {
|
||||||
|
|
||||||
volatile int i;
|
volatile int i;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
pthread_t pthread[1];
|
pthread_t pthread[1];
|
||||||
|
@ -608,12 +609,18 @@ void init_threads() {
|
||||||
for(i = 1; i < THREAD_MAX; i++)
|
for(i = 1; i < THREAD_MAX; i++)
|
||||||
{
|
{
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
pthread_create(pthread, NULL, init_thread, (void*)(&i));
|
ok = (pthread_create(pthread, NULL, init_thread, (void*)(&i)) == 0);
|
||||||
#else
|
#else
|
||||||
DWORD iID[1];
|
DWORD iID[1];
|
||||||
CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID);
|
ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID) != NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
std::cout << "Failed to create thread number " << i << std::endl;
|
||||||
|
Application::exit_with_failure();
|
||||||
|
}
|
||||||
|
|
||||||
// Wait until the thread has finished launching
|
// Wait until the thread has finished launching
|
||||||
while (!Threads[i].running);
|
while (!Threads[i].running);
|
||||||
}
|
}
|
||||||
|
@ -2012,7 +2019,7 @@ namespace {
|
||||||
|
|
||||||
// If another thread has failed high then sp->alpha has been increased
|
// If another thread has failed high then sp->alpha has been increased
|
||||||
// to be higher or equal then beta, if so, avoid to start a PV search.
|
// to be higher or equal then beta, if so, avoid to start a PV search.
|
||||||
localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
if (localAlpha < sp->beta)
|
if (localAlpha < sp->beta)
|
||||||
value = -search_pv(pos, ss, -sp->beta, -localAlpha, newDepth, sp->ply+1, threadID);
|
value = -search_pv(pos, ss, -sp->beta, -localAlpha, newDepth, sp->ply+1, threadID);
|
||||||
else
|
else
|
||||||
|
@ -2780,12 +2787,16 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this thread has been assigned work, launch a search
|
// If this thread has been assigned work, launch a search
|
||||||
if(Threads[threadID].workIsWaiting) {
|
if (Threads[threadID].workIsWaiting)
|
||||||
|
{
|
||||||
|
assert(!Threads[threadID].idle);
|
||||||
|
|
||||||
Threads[threadID].workIsWaiting = false;
|
Threads[threadID].workIsWaiting = false;
|
||||||
if(Threads[threadID].splitPoint->pvNode)
|
if (Threads[threadID].splitPoint->pvNode)
|
||||||
sp_search_pv(Threads[threadID].splitPoint, threadID);
|
sp_search_pv(Threads[threadID].splitPoint, threadID);
|
||||||
else
|
else
|
||||||
sp_search(Threads[threadID].splitPoint, threadID);
|
sp_search(Threads[threadID].splitPoint, threadID);
|
||||||
|
|
||||||
Threads[threadID].idle = true;
|
Threads[threadID].idle = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue