Threading... thing

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Threading... thing

Post by kraftman »

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.
Attachments
autothread.lua
(1.36 KiB) Downloaded 87 times
AutoThread.love
(1.16 KiB) Downloaded 115 times
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Threading... thing

Post by TechnoCat »

Sounds like a pool of threads.
Attachments
thread.PNG
thread.PNG (54.09 KiB) Viewed 1724 times
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Threading... thing

Post by kraftman »

how do i mark it as 0.8?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Threading... thing

Post by Robin »

kraftman wrote:how do i mark it as 0.8?
Just say: "Guys, you need LÖVE 0.8.0 to run it." ;)
Help us help you: attach a .love.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Threading... thing

Post by TechnoCat »

kraftman wrote:how do i mark it as 0.8?
Oh geez. I should've picked up on that when the error was Thread:set.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests