Thread to thread communication in Löve 0.9.0 - Discussion
Posted: Sat Feb 01, 2014 1:57 pm
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!
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!