You are hitting thread start up time…it takes time to start the 3 additional threads.
If you change it to:
a[600] = true
You will get some interesting graphs and on my machine (4 core) the result is different every run.
This might be more what you are looking for. Basically I give each thread 3 seconds to start and become stable before processing the array:
using Plots
using Dates
a = falses(1000)
a[100] = true
function tfunc(a)
stop = Threads.Atomic{Bool}(false)
threadid = zeros(size(a))
start = (second(now()) + 3) % 60
Threads.@threads for i = 1:length(a)
while second(now()) != start
end
threadid[i] = Threads.threadid()
stop[] && break
a[i] && Threads.atomic_xchg!(stop, true)
end
return threadid
end
plot(tfunc(a))