Skip to content

Commit a7381d5

Browse files
committed
Fully yielding locks, no spinning
7 threads: ELO: 2.00 +-2.7 (95%) LOS: 92.4% Total: 20000 W: 3276 L: 3161 D: 13563 There is no functional change in single thread mode Resolves #304
1 parent dc3a5f7 commit a7381d5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class Spinlock {
4848
Spinlock() { lock = 1; } // Init here to workaround a bug with MSVC 2013
4949
void acquire() {
5050
while (lock.fetch_sub(1, std::memory_order_acquire) != 1)
51-
for (int cnt = 0; lock.load(std::memory_order_relaxed) <= 0; ++cnt)
52-
if (cnt >= 10000) std::this_thread::yield(); // Be nice to hyperthreading
51+
while (lock.load(std::memory_order_relaxed) <= 0)
52+
std::this_thread::yield(); // Be nice to hyperthreading
5353
}
5454
void release() { lock.store(1, std::memory_order_release); }
5555
};

0 commit comments

Comments
 (0)