File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 22
22
prog = ProgressMeter. ProgressUnknown (desc= " Attempts at exceeding trigger:" )
23
23
vals = Float64[]
24
24
threadsUsed = Int[]
25
+ lk = ReentrantLock ()
25
26
Threads. @threads for _ in 1 : 1000
26
27
! in (Threads. threadid (), threadsUsed) && push! (threadsUsed, Threads. threadid ())
27
- push! (vals, rand ())
28
- valssum = sum (vals)
29
- if sum (vals) <= trigger
28
+ valssum = lock (lk) do
29
+ push! (vals, rand ())
30
+ return sum (vals)
31
+ end
32
+ if valssum <= trigger
30
33
ProgressMeter. next! (prog)
31
34
elseif ! prog. done
32
35
ProgressMeter. finish! (prog)
47
50
threadsUsed = Int[]
48
51
Threads. @threads for _ in 1 : 100000
49
52
! in (Threads. threadid (), threadsUsed) && push! (threadsUsed, Threads. threadid ())
50
- push! (vals, - rand ())
51
- valssum = sum (vals)
53
+ valssum = lock (lk) do
54
+ push! (vals, - rand ())
55
+ return sum (vals)
56
+ end
52
57
if valssum > thresh
53
58
ProgressMeter. update! (prog, valssum)
54
59
else
You can’t perform that action at this time.
0 commit comments