summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/luv/examples/uvbook/thread-create.lua
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-02-21 11:48:45 +0100
committer ImJezze <jezze@gmx.net>2016-02-21 11:48:45 +0100
commitcc24a339d8c0517259084b5c178d784626ba965c (patch)
tree9868e9687b5802ae0a3733712a3bbeb3bc75c953 /3rdparty/luv/examples/uvbook/thread-create.lua
parentb5daabda5495dea5c50e17961ecfed2ea8619d76 (diff)
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Second attempt
Diffstat (limited to '3rdparty/luv/examples/uvbook/thread-create.lua')
-rw-r--r--3rdparty/luv/examples/uvbook/thread-create.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/3rdparty/luv/examples/uvbook/thread-create.lua b/3rdparty/luv/examples/uvbook/thread-create.lua
new file mode 100644
index 00000000000..4b42587adbf
--- /dev/null
+++ b/3rdparty/luv/examples/uvbook/thread-create.lua
@@ -0,0 +1,38 @@
+local uv = require('luv')
+
+local step = 10
+
+local hare_id = uv.new_thread(function(step,...)
+ local ffi = require'ffi'
+ local uv = require('luv')
+ local sleep
+ if ffi.os=='Windows' then
+ ffi.cdef "void Sleep(int ms);"
+ sleep = ffi.C.Sleep
+ else
+ ffi.cdef "unsigned int usleep(unsigned int seconds);"
+ sleep = ffi.C.usleep
+ end
+ while (step>0) do
+ step = step - 1
+ uv.sleep(math.random(1000))
+ print("Hare ran another step")
+ end
+ print("Hare done running!")
+end, step,true,'abcd','false')
+
+local tortoise_id = uv.new_thread(function(step,...)
+ local uv = require('luv')
+ while (step>0) do
+ step = step - 1
+ uv.sleep(math.random(100))
+ print("Tortoise ran another step")
+ end
+ print("Tortoise done running!")
+end,step,'abcd','false')
+
+print(hare_id==hare_id,uv.thread_equal(hare_id,hare_id))
+print(tortoise_id==hare_id,uv.thread_equal(tortoise_id,hare_id))
+
+uv.thread_join(hare_id)
+uv.thread_join(tortoise_id)