blob: 89c268ca6774b018590b9980700bd1090d2e27cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
local threads = require 'threads'
threads.Threads.serialization('threads.sharedserialize')
local status, tds = pcall(require, 'tds')
tds = status and tds or nil
if not status then return end
local atomic = tds.AtomicCounter()
local numOfThreads = 10
local pool = threads.Threads(numOfThreads)
local steps = 100000
for t=1,numOfThreads do
pool:addjob(function()
for i=1,steps do
atomic:inc()
end
end)
end
pool:synchronize()
print(atomic)
assert(atomic:get() == numOfThreads * steps)
pool:terminate()
print('PASSED')
|