Try to use socket.sleep() instead of os.execute('sleep 1')

pull/1/head
Robert G. Jakabosky 15 years ago
parent 3b8dc38dda
commit a363eb15ec

@ -20,6 +20,18 @@
local llthreads = require"llthreads" local llthreads = require"llthreads"
local sleep
local status, socket = pcall(require,"socket")
if status then
sleep = function(secs)
return socket.sleep(secs)
end
else
sleep = function(secs)
os.execute("sleep " .. tonumber(secs))
end
end
local function detached_thread(...) local function detached_thread(...)
local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...)
-- start detached thread -- start detached thread
@ -43,15 +55,15 @@ end
local thread1 = detached_thread("number:", 1234, "nil:", nil, "bool:", true) local thread1 = detached_thread("number:", 1234, "nil:", nil, "bool:", true)
os.execute("sleep 1"); sleep(1)
local thread2 = print_thread("number:", 1234, "nil:", nil, "bool:", true) local thread2 = print_thread("number:", 1234, "nil:", nil, "bool:", true)
print("thread2:join: results # = ", select('#', thread2:join())) print("thread2:join: results # = ", select('#', thread2:join()))
os.execute("sleep 1"); sleep(1)
local thread3 = pass_through_thread("number:", 1234, "nil:", nil, "bool:", true) local thread3 = pass_through_thread("number:", 1234, "nil:", nil, "bool:", true)
print("thread3:join:", thread3:join()) print("thread3:join:", thread3:join())
os.execute("sleep 1"); sleep(1)

Loading…
Cancel
Save