local lanes = require "lanes".configure() local ThreadList ={} local LindaList = {} local LookList = {} local AtomicCounterList = {} function createRealThread( name, func, args, prior) if(prior == nil)then local thread = lanes.gen("*",{globals = _G},func)(args) else local thread = lanes.gen("*",{globals = _G, priority = prior},func)(args) end ThreadList[name] = thread; end function killRealThread( name, timeout, force) local thread = ThreadList[name] if(thread ~= nil)then return thread:cancel(timeout, force) else return false,"thread not exist" end end function getRealThreadStatus(name) local thread = ThreadList[name] if( thread =~ nil ) return thread.status else return "thread not exist" end end --Lindas are thread safe queues function createLinda(name) linda = lanes.linda() if(name =~ nil)then LindaList[name] = linda; end return linda; end function getLinda(name) return LindaList[name]; end --Must be called from inside the Thread --For yield calls the Windows API call Sleep(0) =? sleep 0 --but Better would for a yield implementation Windows SwitchToThread() API call function sleepRealThread(sec) os.execute("sleep "..sec.."") end function createLock(name) local linda = lanes.linda() local lock = lanes.genlock(linda,name,1) if(name =~ nil)then LookList[name]= lock; end return lock; end function getLock(name) return LookList[name]; end function lockThread(lock) lock(1) end function unlockThread(lock) lock(-1) end --Okay this function doesn't make it simpler :( function createThreadTimer(linda, string_time_def, startin, interval) lanes.timer( linda, string_time_def, startin, interval) end function createAtomicCounter(name) local linda = lanes.linda() local atomic_inc = lanes.genatomic( linda, name) AtomicCounterList[name] = atomic_inc; return atomic_inc; end function getAtomicCounter(name) return AtomicCounterList[name] end