aboutsummaryrefslogblamecommitdiff
path: root/fastnn/threads/test/test-low-level.lua
blob: aea31dbcb1f3820ee801f9e23c99a8136a1fcfb1 (plain) (tree)






































                                                             
local t = require 'libthreads'

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 code = string.format([[
  local t = require 'libthreads'
  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(code)

local thread = t.Thread(code)


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

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

print('| done')