[Lua 5.1] Lua Lanes (Shared global environment) 
8 comments18.02.14 04:44:19 pm

1.69 mb, 328 Downloads
What is Lua Lanes?
Lua Lanes is a multithreading module for Lua 5.1 and Lua 5.2. Just like coroutines, but the best of it is that it does NOT freeze.
What is multithreading?
http://whatis.techtarget.com/definition/multithreading
Here you see I've made a modified version of Lua Lanes that allows you to use the same function environment as the main Lua state, all the memory is shared between CS2D's Lua state and this Lua state. Here's an example of code.
IMPORTANT ADVISE: Memory accessing/writing must be managed with mutexes, using this module always exposes your server to a crash.
I've uploaded this file under this copyright
https://github.com/LuaLanes/lanes/blob/master/COPYRIGHT
Lua Lanes is a multithreading module for Lua 5.1 and Lua 5.2. Just like coroutines, but the best of it is that it does NOT freeze.
What is multithreading?
http://whatis.techtarget.com/definition/multithreading
Here you see I've made a modified version of Lua Lanes that allows you to use the same function environment as the main Lua state, all the memory is shared between CS2D's Lua state and this Lua state. Here's an example of code.
Code:
1
2
3
4
5
6
7
2
3
4
5
6
7
a = 32
function printa()
print( a )
end
StartThread = lanes.gen("*", printa)
StartThread()
function printa()
print( a )
end
StartThread = lanes.gen("*", printa)
StartThread()
IMPORTANT ADVISE: Memory accessing/writing must be managed with mutexes, using this module always exposes your server to a crash.
I've uploaded this file under this copyright
https://github.com/LuaLanes/lanes/blob/master/COPYRIGHT
edited 15×, last 07.08.16 06:59:08 pm
Comments
8 comments



Log in!
You need to log in to be able to write comments!Log in

Before using: call lanes.configure first(without any parameter)
(Hint for newbies)
Code:
1
2
3
2
3
lanes=dofile'lanes.lua'
lanes.configure()
-- Your code here
lanes.configure()
-- Your code here
(Hint for newbies)
@
VADemon: I meant when the main lua state is closed, the generated lua threads (coroutines) will remain in the OS threads that are running. I made a timer in a separate thread to test this and it resulted into a crash of the application (On CS2D, when I changed the map, the server's Lua state died but the threads were still alive thus the timer in them tried to access the dead Lua state).


http://kotisivu.dnainternet.net/askok/bin/lanes/
Starkkz has written:
Reuse opened threads?

(The thread is not automatically closed unless the program itself it's closed).
Reuse opened threads?



