Page 1 of 1
love.run and async threads
Posted: Sun Dec 04, 2016 7:54 pm
by parallax7d
Are messages over channels totally asynchronous, or are they pumped as part of event?
Are threads interacting with imagedata/other love types totally asynch? For example, the mutex operations occur regardless of what point in love.run the main thread is in?
Re: love.run and async threads
Posted: Sun Dec 04, 2016 7:57 pm
by slime
Channels don't use love.event at all. Their operations (push/pop/supply/demand/etc) happen immediately when you call the function.
Re: love.run and async threads
Posted: Sun Dec 04, 2016 7:58 pm
by raidho36
That is exactly right. Channels are completely separate from events pool, you even poll them separately. And a mutex locks whenever it's called to do that, instantly - the other thread may be halfway through executing a math operation. Plus, love.run is not a special function, it's just default main loop in case you don't wish to use your own.
Dang, slime beat me to it.
Re: love.run and async threads
Posted: Sun Dec 04, 2016 8:06 pm
by parallax7d
you guys are quick today!
Just so I get this right, in theory worker threads can access and edit imagedata, and also send messages to main over channels, and the channel method will preempt whatever main is doing, totally and 100% irregardless of what part of the game loop main is currently executing?
*edit: just to note, I understand the cpu scheduler decides when to do these things, so no assumptions can be made about when one thread or the other thread does something. I'm not worried about that, just how threads interrupt the game loop.
Re: love.run and async threads
Posted: Sun Dec 04, 2016 8:13 pm
by raidho36
Threads don't interrupt main game loop nor each other, as long as you're not simultaneously trying to access same exact resource that's locked behind mutex.