Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-low-level.lua « test - github.com/torch/threads-ffi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 823ec7740b9b777144a8fa64ee08d82d901d7a0e (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
31
32
33
34
local t = require 'threads'

local m = t.Mutex()
local c = t.Condition()
print(string.format('| main thread mutex: 0x%x', m:id()))
print(string.format('| main thread condition: 0x%x', c:id()))

local thread = t.Thread(string.format([[
  local t = require 'threads'
  local c = t.Condition(%d)
  print('|| hello from thread')
  print(string.format('|| thread condition: 0x%%x', c:id()))
  print('|| doing some stuff in thread...')
  local x = 0
  for i=1,10000 do
    for i=1,10000 do
      x = x + math.sin(i)
    end
    x = x / 10000
  end
  print(string.format('|| ...ok (x=%%f)', x))
  c:signal()
]], c:id()))

print('| waiting for thread...')
m:lock()
c:wait(m)
print('| thread finished!')

thread:free()
m:free()
c:free()

print('| done')