Threading... thing
Posted: Thu Aug 25, 2011 2:06 pm
I've been messing about with threads a lot and I've come up with this.. thing. I'm not sure how useful it is but i thought I'd share it anyway, at the very least it's some sample code for threading.
It basically allows you to create and run the thread from the main love process, dynamically changing what the thread does depending on what you need it for.
To use it you just need to require the file and add "updateThreads()" to love.update
The commands are:
newThread("name") --returns a new thread that is ready to run your code
thread:run (" some code") -- tells the thread to run the code you give it
and functions you can define are:
runGet[key](data)
runPeek[key](data)
these functions will be run whenever the key is present for the given thread.
inside the thread the main and sub threads and called main_thread and sub_thread.
I've include a demo that tells the thread to write a large image with random data and send it back, while progressively updating the percentage bar.
It basically allows you to create and run the thread from the main love process, dynamically changing what the thread does depending on what you need it for.
To use it you just need to require the file and add "updateThreads()" to love.update
The commands are:
newThread("name") --returns a new thread that is ready to run your code
thread:run (" some code") -- tells the thread to run the code you give it
and functions you can define are:
runGet[key](data)
runPeek[key](data)
these functions will be run whenever the key is present for the given thread.
inside the thread the main and sub threads and called main_thread and sub_thread.
I've include a demo that tells the thread to write a large image with random data and send it back, while progressively updating the percentage bar.