This is simply a "pseudo-lock" when you think about it. You generate captures before you do the SMP search. So idle threads get to sit and wait while you do this. As opposed to sitting and waiting at a lock while you do this. No difference in terms of speed or performance.Joost Buijs wrote:Yes, I know what lock contention is and that is why you want to keep the duration of the lock as short as possible.mcostalba wrote: Regarding std::set performance, you are aiming at the wrong target, here is reducing lock contention the real target: in case lock is already held, the thread is suspended and it will be resumed at a random, possibly long time, depending on the thread scheduler, this is much worse than the time spent to look up a std::set of just few moves.
In my engine I do the following:
Try the hash move (if available) before any move generation at all.
Then I generate all captures and sort them with an insertion sort, this happens before I call the SMP search.
Now I can simply pick the captures from a list which goes very quick.
The only time I really get a problem with lock contention is when I run out of captures and have to generate the non captures and sort them.
That is why I want to try to generate all moves at once, it also makes the code a lot cleaner and probably faster.
I don't do a "sort". I select a move when one is needed. I've tried this many times but it has always slowed me down too much. Particularly when you don't have a hash move or a good capture, and you generate all moves and sort. And every other ply only needs one move to fail high wasting the sort effort... I also try killers, counter-moves, etc, before generating the non-captures, which has always been faster for me.