758 posts
Location
Budapest, Hungary
Posted 07 March 2013 - 10:26 AM
Are there any disadvantages of using coroutines? (Massive lag doesn't count…) Because I've heard "they're spawning Java threads" or something like that…
148 posts
Posted 07 March 2013 - 10:38 AM
Any CC computer is a coroutine…So it might have disadvantages, but I wouldn't care about that :P/>
(because I don't think your programm will start thousands of coroutines)
839 posts
Location
England
Posted 07 March 2013 - 10:51 AM
If you read the wiki fully it says that problem was fixed a while ago.
Coroutines used to accidentally spawn Java threads (Java's very good at leaking memory) but they don't anymore, now they are just fancy functions, so don't worry about them, use them to your heart's content.
Just remember, coroutines aren't the same as multithreading, they are separate routines that run synchronously (in the same time frame) but they can be stopped and started, so they are like threads in that processes are scheduled to run in a different order, but they don't run at the same time as each other, and you can schedule them to run when you want them to rather than leaving it up to chance and relying on events/callbacks.
8543 posts
Posted 07 March 2013 - 11:10 AM
If you read the wiki fully it says that problem was fixed a while ago.
Coroutines used to accidentally spawn Java threads (Java's very good at leaking memory) but they don't anymore, now they are just fancy functions, so don't worry about them, use them to your heart's content.
Just remember, coroutines aren't the same as multithreading, they are separate routines that run synchronously (in the same time frame) but they can be stopped and started, so they are like threads in that processes are scheduled to run in a different order, but they don't run at the same time as each other, and you can schedule them to run when you want them to rather than leaving it up to chance and relying on events/callbacks.
I don't think you understand coroutines very well.
758 posts
Location
Budapest, Hungary
Posted 07 March 2013 - 11:29 AM
Thanks everybody. I wasn't sure about that "spawning threads" part.
839 posts
Location
England
Posted 07 March 2013 - 01:13 PM
If you read the wiki fully it says that problem was fixed a while ago.
Coroutines used to accidentally spawn Java threads (Java's very good at leaking memory) but they don't anymore, now they are just fancy functions, so don't worry about them, use them to your heart's content.
Just remember, coroutines aren't the same as multithreading, they are separate routines that run synchronously (in the same time frame) but they can be stopped and started, so they are like threads in that processes are scheduled to run in a different order, but they don't run at the same time as each other, and you can schedule them to run when you want them to rather than leaving it up to chance and relying on events/callbacks.
I don't think you understand coroutines very well.
Coroutines are processed sequentially (ie only one is processed at a time) true threads are not.
True threads run simultaneously, they do not simply pass the baton like coroutines.
Coroutines do pass the baton fluidly because their state is stored, however they are ultimately still set in sequence and cannot run at the exact same time like threads can.
Yes you can feign asynchronous file reading by having the file read bit by bit (no pun intended) but as the coroutine must still be manually scheduled and processing must be passed between them, it's not truly asynchronous processing, it's merely scheduled processing. If it were truly asynchronous, the file reading would not be dependant on the yielding of the other process, it could complete regardless of how long the other process takes.
1511 posts
Location
Pennsylvania
Posted 07 March 2013 - 02:00 PM
Just read this if you have any further questions regarding
Lua's Coroutines. I think everyone should read the Lua Reference Manual before posting topics, but eh. I have no say in Human Rights :P/>