Multiple threads from one file?

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
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post by Astusvis »

Robin wrote:Can't you put the bulk of the code in a big loop instead?
me == stupid

EDIT: Why won't this code start the thread? The thread code itself has no problems in it.

Code: Select all

for i=1, threads do
	thread[i] = {thread = love.thread.newThread("genimage" .. i, "genimage.lua"), image = nil, depth = nil}
	thread[i].thread:start()
	print("Created/started thread no. " .. i)
end
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Multiple threads from one file?

Post by TechnoCat »

Astusvis wrote:EDIT: Why won't this code start the thread? The thread code itself has no problems in it.
Seems to me that is exactly the problem. Sounds like your thread code crashes.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiple threads from one file?

Post by bartbes »

It seems you are still working with love.image at the same time in multiple threads, which won't work in 0.7.2.

Also, killing, regardless of the lua code has finished, can have very bad effects, I've had love crash because of it, or worse, in a deadlock.
User avatar
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post by Astusvis »

Oh, I forgot that I'd removed the any image references and used TSerial along with a table to just gather pixel data.
I've also put it into a loop.

The thing is the code isn't even being run; I put a print("Thread loaded") at the top and the console was blank.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Multiple threads from one file?

Post by Boolsheet »

LÖVE pushes the Lua error to "error" if something in the script went wrong.
Get it with thread:receive("error").
Shallow indentations.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Multiple threads from one file?

Post by TechnoCat »

Boolsheet wrote:LÖVE pushes the Lua error to "error" if something in the script went wrong.
Get it with thread:receive("error").
Inserting into the wiki. Not really sure where!
User avatar
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post by Astusvis »

Woah, that helped alot.
Do threads happen to be copied over to a different folder before being run, by any chance? Because that MUST be happening.

Basically, the thread of genimage.lua can't find TSerial.lua, although main.lua can...

Also, I'd put another reference to the error retrieving in Thread:reveive()
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiple threads from one file?

Post by bartbes »

You have to load love.filesystem first.
User avatar
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post by Astusvis »

_
Last edited by Astusvis on Tue Oct 06, 2015 9:09 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiple threads from one file?

Post by Robin »

I'm not sure what the threads do, but aren't they in a loop? And if they're producing information, where is it kept?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 7 guests