forked from torch/threads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-threads.lua
More file actions
35 lines (27 loc) · 736 Bytes
/
test-threads.lua
File metadata and controls
35 lines (27 loc) · 736 Bytes
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
31
32
33
34
35
local threads = require 'threads'
local nthread = 4
local njob = 10
local msg = "hello from a satellite thread"
local pool = threads.Threads(
nthread,
function(threadid)
print('starting a new thread/state number ' .. threadid)
gmsg = msg -- get it the msg upvalue and store it in thread state
end
)
local jobdone = 0
for i=1,njob do
pool:addjob(
function()
print(string.format('%s -- thread ID is %x', gmsg, __threadid))
return __threadid
end,
function(id)
print(string.format("task %d finished (ran on thread ID %x)", i, id))
jobdone = jobdone + 1
end
)
end
pool:synchronize()
print(string.format('%d jobs done', jobdone))
pool:terminate()