Search code examples
multithreadingluacoroutine

Are coroutines in Lua actually multithreaded?


Lua coroutines provide cooperative multithreading, and there can only be one coroutine running at a time. So, how are they even different from a normal block of code (keeping aside cases where there is a wait time specified in the code)? Also, do coroutines actually run on different threads?


Solution

  • how are they even different from a normal block of code (keeping aside cases where there is a wait time specified in the code)?

    Because when you return from the middle of a normal function, you can't later just jump back to where you were.

    Also, do coroutines actually run on different threads?

    No. Only one is running at a time.