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

github.com/torch/threads-ffi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlake4790k <lake4790k@users.noreply.github.com>2016-05-13 20:52:41 +0300
committerlake4790k <lake4790k@users.noreply.github.com>2016-05-13 20:52:41 +0300
commitd774ae79aed1b7f07ff49749847999e74a0e6caa (patch)
tree5cee7acb7b5b7b5f73a4c94675baf07d51c55f2e
parent8e8223d60d43468d327fbb8511d15e941aa0a9a6 (diff)
test for AtomicCounter
-rw-r--r--test/test-atomic.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/test-atomic.lua b/test/test-atomic.lua
new file mode 100644
index 0000000..89c268c
--- /dev/null
+++ b/test/test-atomic.lua
@@ -0,0 +1,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') \ No newline at end of file