Hi,
I've been doing quite some work with threads in 0.8.0 and was familiar with that interface. The new interface has some improvements, but there's also a few features I'm missing and I'd like to hear/discuss some best practices and solutions to a few problems I have.
So, general question: How do YOU handle thread communication in 0.9.x?
Follow up questions (Note: I often use threads to render an image or similar, so I need input arguments - image size, width, height etc - and output arguments - the image. I also like to have some way of controlling the thread while it's running and a percentage update which tells me how far the thread has gotten):
1) When I start mutliple threads, all doing the same thing (and using the same file), how do you make sure channels are created and associated with the correct thread? For example, inside the thread, I use:
chanPercentageOut = love.thread.getChannel("percentage")
But then they'd all use the same value
2) Did anyone come up with a nice way of passing (key, value) pairs through channels? The 0.8.0 method had the nice feature to give a name (or key) to the value by which it could be retreived (with the disadvantage of it overwriting previous values with the same key). This is no longer possible. Still, sometimes, I like to mimik that behaviour, since otherwise I have a huge amount of channels that I need to create, if I have many kinds of values passed (of the same type, that is. Otherwise I could just identify them by the type).
One way I can come up with is to write a library that creates a channel automatically when it gets a new type of value (or asks for one). But this all seems very cumbersome...
Any discussion on thread-to-thread communication is welcome!
Thread to thread communication in Löve 0.9.0 - Discussion
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Thread to thread communication in Löve 0.9.0 - Discussion
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
For 1: I have no idea.
As for 2:
I just create a slew of named channels for each key/value pair I want to send. That may not be the best way of doing things.
Anyway, if you want to send multiple values at once, you can send a flat table that contains the key/value pairs you want to send.
As for 2:
I just create a slew of named channels for each key/value pair I want to send. That may not be the best way of doing things.
Anyway, if you want to send multiple values at once, you can send a flat table that contains the key/value pairs you want to send.
Help us help you: attach a .love.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Hum, I don't need multiple things at the same time, but this is still an idea: I can simply use:Robin wrote: Anyway, if you want to send multiple values at once, you can send a flat table that contains the key/value pairs you want to send.
Code: Select all
channelOut:push( {key="percentage", value=10} )
This doesn't replace a
Code: Select all
thread:demand("percentage")
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Channels aren't ever associated to any thread, which is kind of the idea behind them.
From what I can tell, what you want to do is talk to a thread "in private", in this case, use an unnamed channel, and pass it to [wiki]Thread:start[/wiki] for instance.
Regarding key/value pairs, this is trivially re-implemented using channel:push{[key] = value}. (And then another trivial unpacking on the other end.)
From what I can tell, what you want to do is talk to a thread "in private", in this case, use an unnamed channel, and pass it to [wiki]Thread:start[/wiki] for instance.
Regarding key/value pairs, this is trivially re-implemented using channel:push{[key] = value}. (And then another trivial unpacking on the other end.)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Oh, man, I didn't realise this was possible! That solves all kinds of problems.bartbes wrote:pass it to [wiki]Thread:start[/wiki] for instance.
Help us help you: attach a .love.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Same here. Awesome, this will do. And yes, that was what I was looking for.Robin wrote:Oh, man, I didn't realise this was possible! That solves all kinds of problems.bartbes wrote:pass it to [wiki]Thread:start[/wiki] for instance.
Together with the table method you mentioned, this should solve all my problems.
Thanks!
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Follow-up question:
Is there a way to get the number of currently running threads in 0.9.0?
I used to just do:
#love.thread.getThreads()
but that function got removed...
Is there a way to get the number of currently running threads in 0.9.0?
I used to just do:
#love.thread.getThreads()
but that function got removed...
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Thread to thread communication in Löve 0.9.0 - Discussio
Not without keeping your own list of the threads you've created - which you might want to do anyway.
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 0 guests