Threads in 0.9.0?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: Threads in 0.9.0?

Post by AntonioModer »

I modify code of Helvecta, thanks.
And test on my quad-core PC on Windows 8.1.
This is cool, thanks for all developers of this module! :awesome:

threadsExample.love
(2.24 KiB) Downloaded 596 times
Last edited by AntonioModer on Fri Aug 14, 2015 7:40 am, edited 2 times in total.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Threads in 0.9.0?

Post by Germanunkol »

Is this a single CPU? Cause otherwise this would mean threadding is very inefficient here - it should spread the threads accross the cpus...
Or is it showing the summed up work of all CPUs on your CPU monitor?
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: Threads in 0.9.0?

Post by AntonioModer »

Germanunkol wrote:Is this a single CPU?
4 cores
Germanunkol wrote:Or is it showing the summed up work of all CPUs on your CPU monitor?
Yes
PeachBear
Prole
Posts: 2
Joined: Tue Feb 07, 2017 7:29 pm

Re: Threads in 0.9.0?

Post by PeachBear »

Posting this for my sake and anyone else who comes looking for this:

When passing arguments to Thread:start() you can use the following to capture multiple args into a table for later use. I found this to be useful for passing a varying number of arguments to start().

Code: Select all

-- thread.lua
-- ### gather args
local args = {}
local x = 1
while true do
    local o = select(x, ...)
    if o == nil then
        break
    end
    table.insert(args, o)
    x = x + 1
end
Then in your main.lua script you might have something like this:

Code: Select all

-- main.lua
function love.load()
    thread = love.thread.newThread("thread.lua")
    channel = love.thread.getChannel("test")
    thread:start('5000000000', 'Finished')
end
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Threads in 0.9.0?

Post by bartbes »

You're only 1.5 years late to the party…

I'd also like to point out you could replace your entire first snippet with 'local args = {...}'.
PeachBear
Prole
Posts: 2
Joined: Tue Feb 07, 2017 7:29 pm

Re: Threads in 0.9.0?

Post by PeachBear »

You're only 1.5 years late to the party…
Very true. That being said, in my recent searches I wasn't able to find much else about threads and this post is still linked on the wiki page for threads.
I'd also like to point out you could replace your entire first snippet with 'local args = {...}'.
That certainly makes things a lot simpler, thanks! I've only been working with Lua/LOVE for about a month now so I'm still learning the tricks of the trade.
Post Reply

Who is online

Users browsing this forum: No registered users and 101 guests