Skip to content

Commit 4f55ed1

Browse files
committed
Revert using exceptions
Due to crashes. It will be reapplied once we understand what's happening. No functional change.
1 parent a6c0ba2 commit 4f55ed1

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ifeq ($(COMP),clang)
232232
endif
233233

234234
### 3.2 General compiler settings
235-
CXXFLAGS = -Wall -Wcast-qual -fno-rtti $(EXTRACXXFLAGS)
235+
CXXFLAGS = -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
236236

237237
ifeq ($(comp),gcc)
238238
CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow

src/search.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <cassert>
2222
#include <cmath>
2323
#include <cstring>
24-
#include <exception>
2524
#include <iostream>
2625
#include <sstream>
2726

@@ -105,8 +104,6 @@ namespace {
105104
bool refutes(const Position& pos, Move first, Move second);
106105
string uci_pv(const Position& pos, int depth, Value alpha, Value beta);
107106

108-
class stop : public std::exception {};
109-
110107
struct Skill {
111108
Skill(int l) : level(l), best(MOVE_NONE) {}
112109
~Skill() {
@@ -359,9 +356,7 @@ namespace {
359356
// research with bigger window until not failing high/low anymore.
360357
while (true)
361358
{
362-
try {
363-
bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false);
364-
} catch (stop&) {}
359+
bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false);
365360

366361
// Bring to front the best move. It is critical that sorting is
367362
// done with a stable algorithm because all the values but the first
@@ -546,13 +541,10 @@ namespace {
546541
if (PvNode && thisThread->maxPly < ss->ply)
547542
thisThread->maxPly = ss->ply;
548543

549-
if (Signals.stop || thisThread->cutoff_occurred())
550-
throw stop();
551-
552544
if (!RootNode)
553545
{
554546
// Step 2. Check for aborted search and immediate draw
555-
if (pos.is_draw() || ss->ply > MAX_PLY)
547+
if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY)
556548
return DrawValue[pos.side_to_move()];
557549

558550
// Step 3. Mate distance pruning. Even if we mate at the next move our score
@@ -1007,6 +999,13 @@ namespace {
1007999
alpha = splitPoint->alpha;
10081000
}
10091001

1002+
// Finished searching the move. If Signals.stop is true, the search
1003+
// was aborted because the user interrupted the search or because we
1004+
// ran out of time. In this case, the return value of the search cannot
1005+
// be trusted, and we don't update the best move and/or PV.
1006+
if (Signals.stop || thisThread->cutoff_occurred())
1007+
return value; // To avoid returning VALUE_INFINITE
1008+
10101009
if (RootNode)
10111010
{
10121011
RootMove& rm = *std::find(RootMoves.begin(), RootMoves.end(), move);
@@ -1697,27 +1696,22 @@ void Thread::idle_loop() {
16971696

16981697
activePosition = &pos;
16991698

1700-
try {
1701-
switch (sp->nodeType) {
1702-
case Root:
1703-
search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1704-
break;
1705-
case PV:
1706-
search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1707-
break;
1708-
case NonPV:
1709-
search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1710-
break;
1711-
default:
1712-
assert(false);
1713-
}
1714-
1715-
assert(searching);
1716-
}
1717-
catch (stop&) {
1718-
sp->mutex.lock(); // Exception is thrown out of lock
1699+
switch (sp->nodeType) {
1700+
case Root:
1701+
search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1702+
break;
1703+
case PV:
1704+
search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1705+
break;
1706+
case NonPV:
1707+
search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
1708+
break;
1709+
default:
1710+
assert(false);
17191711
}
17201712

1713+
assert(searching);
1714+
17211715
searching = false;
17221716
activePosition = NULL;
17231717
sp->slavesMask &= ~(1ULL << idx);

0 commit comments

Comments
 (0)