aboutsummaryrefslogtreecommitdiff
path: root/fastnn/threads/test/test-low-level.lua
diff options
context:
space:
mode:
authorTed Yin <[email protected]>2015-08-31 12:03:15 +0800
committerTed Yin <[email protected]>2015-08-31 12:03:15 +0800
commit447bd1ec6b7be07f22653874fc9db84c9b6a9f9a (patch)
tree0268d85a8f75783daaa6b182bee1338dcd504f48 /fastnn/threads/test/test-low-level.lua
parentcad144243b898a7bed91c18572bf42944e9db3b3 (diff)
parent3463789202b7ededf5074b199d5122ca85d328ea (diff)
Merge pull request #4 from uphantom/master
fastnn first version, include follow submodular
Diffstat (limited to 'fastnn/threads/test/test-low-level.lua')
-rw-r--r--fastnn/threads/test/test-low-level.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/fastnn/threads/test/test-low-level.lua b/fastnn/threads/test/test-low-level.lua
new file mode 100644
index 0000000..aea31db
--- /dev/null
+++ b/fastnn/threads/test/test-low-level.lua
@@ -0,0 +1,39 @@
+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')