mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 09:47:46 +00:00
Fix the counter in for_each_index_with_workers going out of scope before workers finish.
This commit is contained in:
+7
-2
@@ -135,10 +135,15 @@ struct ThreadPool : public std::vector<Thread*> {
|
|||||||
typename Detail::TypeIdentity<IndexT>::Type end,
|
typename Detail::TypeIdentity<IndexT>::Type end,
|
||||||
FuncT func)
|
FuncT func)
|
||||||
{
|
{
|
||||||
std::atomic<IndexT> i_atomic = begin;
|
// This value must outlive the function call.
|
||||||
|
// It's fairly safe if we make it static
|
||||||
|
// because for_each_index_with_workers
|
||||||
|
// is not reentrant nor thread safe.
|
||||||
|
static std::atomic<IndexT> i_atomic;
|
||||||
|
i_atomic.store(begin);
|
||||||
|
|
||||||
execute_with_workers(
|
execute_with_workers(
|
||||||
[&i_atomic, end, func](Thread& th) mutable {
|
[end, func](Thread& th) mutable {
|
||||||
for(;;) {
|
for(;;) {
|
||||||
const auto i = i_atomic.fetch_add(1);
|
const auto i = i_atomic.fetch_add(1);
|
||||||
if (i >= end)
|
if (i >= end)
|
||||||
|
|||||||
Reference in New Issue
Block a user