【问题标题】:Are coroutines in Lua actually multithreaded?Lua 中的协程实际上是多线程的吗?
【发布时间】:2021-09-01 10:57:00
【问题描述】:

Lua 协程提供协作多线程,一次只能运行一个协程。那么,它们与普通代码块有什么不同(撇开代码中指定等待时间的情况除外)?另外,协程真的运行在不同的线程上吗?

【问题讨论】:

  • there can only be one coroutine running at a time - 是的。 do coroutines actually run on different threads? - 没有。how are they even different from a normal block of code? - 每个协程都有自己的堆栈
  • 请参考 Lua 参考手册。 Lua 中的编程还深入介绍了协程。不要将 Lua 线程与系统线程混淆。

标签: multithreading lua coroutine


【解决方案1】:

它们与普通代码块有何不同(撇开代码中指定等待时间的情况除外)?

因为当你从一个普通函数的中间返回时,你以后不能直接跳回到原来的位置。

另外,协程真的在不同的线程上运行吗?

没有。一次只运行一个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多