love.thread?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
love.thread?
ok so i want to make a connect 4 game using minimax tree AI. i would like to run the the AI in another thread so it can constantly build the tree to decide on next move. how ever im unclear on how to use love.thread, i read that you should not call love.graphics functions from a love thread and from what i can tell you run the whole file in a thread instead of just a function. how dose any of this work? what functions dose it call, how do i receive and send messages to/from it? any clarification would be nice
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: love.thread?
Someone (I don't recall who) made this quick thing using threads: http://dl.dropbox.com/u/4214717/threads3.love
If you have a LuaJIT-compiled version of LÖVE you can use that to see incredible speed differences, too.
If you have a LuaJIT-compiled version of LÖVE you can use that to see incredible speed differences, too.
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: love.thread?
thanks but this crashes as for the LuaJIT i have it and am going to be using it for testing but i would like to make something that would work in plain Lua efficiently enough to be played. i will still likely test it with LuaJIT just to see how powerful the AI could be.
Re: love.thread?
Ah yeah, threads3... That damn thing still doesn't run properly.
If you're using 0.7.1 it probably crashes because the threads create multiple ImageData at the same time. Try to avoid ImageData in threads for the moment or at least don't access/manipulate them at the same time.
The threads that 'love.thread.newThread' creates are completely separate Lua environments. They will execute the Lua script you are passing to newThread and stop once they reach the end or 'return' out of it.
To communicate with the 'main' (This is the one which runs main.lua, polls all events, draws, etc...) and other threads every thread has a synchronized area allocated to it that can be accessed by all of them. Think of it as a Lua table that only takes strings for keys and data for values (no tables or functions). A thread can put a value in its own or one of the other's table which can be accessed by any thread by waiting until a certain key is set or by continuously polling for changes. There are no events or callbacks, it's up to you if it should work like a stack that grows or only with some special magic keys.
Some love modules are not meant to be used in threads. Besides 'love.graphics' I know of 'love.event' that is not safe for threading. Also, as noted above, avoid 'love.image' for now. I've informed the developers about it and they're looking into it.
If you're using 0.7.1 it probably crashes because the threads create multiple ImageData at the same time. Try to avoid ImageData in threads for the moment or at least don't access/manipulate them at the same time.
The threads that 'love.thread.newThread' creates are completely separate Lua environments. They will execute the Lua script you are passing to newThread and stop once they reach the end or 'return' out of it.
To communicate with the 'main' (This is the one which runs main.lua, polls all events, draws, etc...) and other threads every thread has a synchronized area allocated to it that can be accessed by all of them. Think of it as a Lua table that only takes strings for keys and data for values (no tables or functions). A thread can put a value in its own or one of the other's table which can be accessed by any thread by waiting until a certain key is set or by continuously polling for changes. There are no events or callbacks, it's up to you if it should work like a stack that grows or only with some special magic keys.
Some love modules are not meant to be used in threads. Besides 'love.graphics' I know of 'love.event' that is not safe for threading. Also, as noted above, avoid 'love.image' for now. I've informed the developers about it and they're looking into it.
Shallow indentations.
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: love.thread?
so how do a access this common area? i would be satisfied with almost any exchange of data between threads. i just need a way to communicate between threads, i can figure out the rest.
edit: ok i think i get it, send allows you to 'send' a value and 'demand' allows you to get a value. ill play around with it some and ask more questions if i need to thanks!!
edit2: i think 'receive' will work well for me here, i think i got this.
edit: ok i think i get it, send allows you to 'send' a value and 'demand' allows you to get a value. ill play around with it some and ask more questions if i need to thanks!!
edit2: i think 'receive' will work well for me here, i think i got this.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest