@@ -48,7 +48,7 @@ type Search struct {
4848 once sync.Once
4949 allowedMoves []Move
5050 bestScore [2 ]int
51- sync.Mutex
51+ // sync.Mutex
5252 cancel chan bool
5353 bestMove , ponderMove Move
5454 gt * GameTimer
@@ -91,15 +91,15 @@ func NewSearch(params SearchParams, gt *GameTimer, uci *UCIAdapter, allowedMoves
9191func (s * Search ) sendResult () {
9292 // UCIInfoString(fmt.Sprintf("Search %d aborting...\n", search_id))
9393 s .once .Do (func () {
94- s .Lock ()
94+ // s.Lock()
9595 if s .uci != nil {
9696 if s .ponder {
9797 s .uci .result <- s .Result () // queue result to be sent when requested by GUI.
9898 } else {
9999 s .uci .BestMove (s .Result ()) // send result immediately
100100 }
101101 }
102- s .Unlock ()
102+ // s.Unlock()
103103 })
104104}
105105
@@ -159,35 +159,33 @@ func (s *Search) iterativeDeepening(brd *Board) int {
159159 inCheck := brd .InCheck ()
160160
161161 for d := 1 ; d <= s .maxDepth ; d ++ {
162- select {
163- case <- s .cancel :
164- return sum
165- default :
166- }
167162
168163 stk [0 ].inCheck = inCheck
169164 guess , total = s .ybw (brd , stk , s .alpha , s .beta , d , 0 , Y_PV , SP_NONE , false )
170165 sum += total
171166
167+ select { // if the cancel signal was received mid-search, the current guess is not useful.
168+ case <- s .cancel :
169+ return sum
170+ default :
171+ }
172+
172173 if stk [0 ].pv .m .IsMove () {
173- s .Lock ()
174+ // s.Lock()
174175 s .bestMove , s .bestScore [c ] = stk [0 ].pv .m , guess
175176 if stk [0 ].pv .next != nil {
176177 s .ponderMove = stk [0 ].pv .next .m
177178 }
178- s .Unlock ()
179+ // s.Unlock()
179180 stk [0 ].pv .SavePV (brd , d , guess ) // install PV to transposition table prior to next iteration.
180181 } else {
181182 s .sendInfo ("Nil PV returned to ID\n " )
182183 }
183- // nodes_per_iteration[d] += total
184184 if d >= COMMS_MIN && (s .verbose || s .uci != nil ) { // don't print info for first few plies to reduce communication traffic.
185185 s .uci .Info (Info {guess , d , sum , s .gt .Elapsed (), stk })
186186 }
187187 }
188188
189- // TODO: BUG: 'orphaned' workers occasionally still processing after ID loop
190-
191189 return sum
192190}
193191
0 commit comments