Skip to content

Commit ca0006c

Browse files
authored
Fix threadpool hangs with numThreads >= 257 (#623)
1 parent e443a8b commit ca0006c

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

constantine.nimble

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ const testDescThreadpool: seq[string] = @[
700700
"benchmarks-threadpool/matrix_transposition/threadpool_transposes.nim",
701701
"benchmarks-threadpool/histogram_2D/threadpool_histogram.nim",
702702
"benchmarks-threadpool/logsumexp/threadpool_logsumexp.nim",
703+
"tests/threadpool/t_257_threads.nim",
703704
]
704705

705706
const testDescMultithreadedCrypto: seq[string] = @[

constantine/threadpool/crossthread/backoff.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const # bitfield setup
6060
# - Xeon Platinum 8490H, 60C/120T per socket
6161
# - up to 8 sockets: 960 threads
6262

63-
kPreWaitShift = 8'u32
63+
kPreWaitShift = 16'u32
6464
kPreWait = 1'u32 shl kPreWaitShift
6565
kWait = 1'u32
6666
kCommitToWait = kWait - kPreWait

tests/threadpool/t_257_threads.nim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import constantine/threadpool
2+
3+
# Just check this won't hang
4+
const numThreads = 257
5+
const numTasks = numThreads * 4
6+
7+
proc nothing() =
8+
discard
9+
10+
proc main() =
11+
echo "\n=============================================================================================="
12+
echo "Running 'tests/threadpool/t_257_threads.nim'"
13+
echo "=============================================================================================="
14+
15+
let tp = Threadpool.new(numThreads = numThreads)
16+
for _ in 0 ..< numTasks:
17+
tp.spawn nothing()
18+
tp.shutdown()
19+
20+
echo "ok"
21+
22+
main()

0 commit comments

Comments
 (0)