multithreading love with love.thread

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
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: multithreading love with love.thread

Post by Jasoco »

TechnoCat wrote:
Jasoco wrote:Maybe if you added a thread stopping code to a love.run() function of your own that would be called when you quit, it would end better instead of crashing. How exactly would you go about stopping any running threads in the middle of their run? Apparently it's not thread:stop().
Try Thread:kill() in love.quit()
Nope. That just caused it to freeze with the colorful spinning wheel. Rather than quitting and crashing.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: multithreading love with love.thread

Post by bartbes »

Please don't call kill, didn't I put a warning on the wiki?!
Anyway, I don't think this is a bug with threading though, what happens when you use a really basic thread, or when you put the thread code in the main thread?
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: multithreading love with love.thread

Post by Jasoco »

Well, I did notice if I quit right after the first image, but before the second one, it doesn't crash. So maybe it has something to do with calling it more than once?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: multithreading love with love.thread

Post by TechnoCat »

I updated the original post to not have dumb loops in it. Also, you can quit the thread with 'q'.
User avatar
saiko-chriskun
Prole
Posts: 6
Joined: Wed Dec 01, 2010 8:13 pm

Re: multithreading love with love.thread

Post by saiko-chriskun »

what are the advantages of love.thread over lua's built-in coroutines?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: multithreading love with love.thread

Post by TechnoCat »

saiko-chriskun wrote:what are the advantages of love.thread over lua's built-in coroutines?
Coroutines are not truly threads. It is my understanding coroutines in Lua will only execute one thread at a time.

http://lua-users.org/wiki/CoroutinesTutorial
Coroutines in Lua are not operating system threads or processes. Coroutines are blocks of Lua code which are created within Lua, and have their own flow of control like threads. Only one coroutine ever runs at a time, and it runs until it activates another coroutine, or yields (returns to the coroutine that invoked it).
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: multithreading love with love.thread

Post by Mud »

saiko-chriskun wrote:what are the advantages of love.thread over lua's built-in coroutines?
Coroutines don't allow concurrent execution. If you resume a coroutine, the coroutine has to yield before control returns to the caller. You can do cooperative multitasking by cycling through coroutines and resuming them (each coroutine decides how much time it gets, and can potentially never yield controller), whereas threads allow preemptive multitasking (the task scheduler decides how much time a thread gets).
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: multithreading love with love.thread

Post by TechnoCat »

How would I pass a luasocket connection to a thread? EDIT: https://bitbucket.org/rude/love/issue/2 ... assing-non

Also, can threads create threads? EDIT: require love.filesystem first.
Last edited by TechnoCat on Thu Jun 23, 2011 11:24 pm, edited 1 time in total.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: multithreading love with love.thread

Post by Taehl »

I don't think you can pass connections to threads because, unless I'm mistaken, you can only pass strings and I don't think you can serialize a connection.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: multithreading love with love.thread

Post by slime »

You can send and received pretty much anything (including userdata) except tables, AFAIK.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests