lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 11/8/06, Thomas Harning Jr. <harningt@gmail.com> wrote:
Sorry to burst your bubble... but Lua does not have pre-emptive
threading built in...  However in a game engine, use of Lua's
co-routines can make game logic very simple (each entity gets its own
coroutine and you cycle through it for operations).

I got the impression lua could work with real threads from here:

http://www.cs.princeton.edu/~diego/professional/luathread/examples.html

Are these examples out of date or deprecated?

Threading in a game engine can be tricky, you'll want to setup some
specific threads to queue operations.  Ex:  One thread doing game
logic (looping over the co-routines and handling events), one thread
doing graphics, one thread for sound, one thread for networking
code...

I was thinking of something more general, somethin like this (pseudo code):

function map(fn, list)
   function _map(fn, half_list)
       local result
       for item in half_list do
           result.append(fn(item))
       end
       return result
   end
   list_a, list_b = split(list)
   thread_a = thread.create(_map, list_a)
   thread_b = thread.create(_map, list_b)
   return thread_a.join() + thread_b.join()
end

Which could possibly be applied to any general looping operation,
depending on a threshold, and the number of cores / cpus. This sort of
construct could be scaled to as many cores / cpu's are available.

Can Lua, or a Lua extension provide this kind of threading construct?

-Sw.