Julia already notes that threadid based buffers are dangerous as you can get yield points within loops where the threadid switches. So far we've gotten away with this. In Julia v1.12, Threads.nthreads() reports the number of worker threads, but the worker threads are numbered from nthreads(:interactive) .+ (1:nthreads(:default)). Thus when we allocate a buffer of Threads.nthreads(), but then try to index on Threads.threadid(), we wind up trying to access an element at Threads.nthreads()+1.
We really should find a correct way of doing thread-safe buffer arrays. Perhaps @fredrikekre can help. In the meantime, I think tid = mod(Threads.threadid(), Threads.nthreads()) + 1 would restore existing behavior.
Julia already notes that threadid based buffers are dangerous as you can get yield points within loops where the threadid switches. So far we've gotten away with this. In Julia v1.12,
Threads.nthreads()reports the number of worker threads, but the worker threads are numbered fromnthreads(:interactive) .+ (1:nthreads(:default)). Thus when we allocate a buffer ofThreads.nthreads(), but then try to index onThreads.threadid(), we wind up trying to access an element atThreads.nthreads()+1.We really should find a correct way of doing thread-safe buffer arrays. Perhaps @fredrikekre can help. In the meantime, I think
tid = mod(Threads.threadid(), Threads.nthreads()) + 1would restore existing behavior.