Jump to content




Disadvantages of coroutines


  • You cannot reply to this topic
6 replies to this topic

#1 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, 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...

#2 JokerRH

  • Members
  • 147 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)

#3 Pharap

  • Members
  • 816 posts
  • LocationEngland

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.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 March 2013 - 11:10 AM

View PostPharap, on 07 March 2013 - 10:51 AM, said:

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.

#5 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 07 March 2013 - 11:29 AM

Thanks everybody. I wasn't sure about that "spawning threads" part.

#6 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 07 March 2013 - 01:13 PM

View PostLyqyd, on 07 March 2013 - 11:10 AM, said:

View PostPharap, on 07 March 2013 - 10:51 AM, said:

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.

#7 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users