支持纤程/协程的脚本语言?

发布于 2024-08-15 16:52:06 字数 333 浏览 2 评论 0原文

我想用一种支持通过光纤(又名协程,又名用户模式线程)并发的语言启动一个新的网络服务器项目。确定我的选项到底是什么非常困难,因为术语“协程”似乎被广泛地用来表示各种事物,而“纤程”几乎专门用于指代 Win32 API。

就这个问题而言,协程/纤程:

  • 支持通过从嵌套函数内(即调用协程/纤程的调用堆栈中的任意深度)向调用函数产生结果来暂停执行的方法,
  • 支持将控制权转移到另一个任意协程在其当前执行点(即屈服于未调用您的协程的协程)

我的语言选项是什么?我知道 Ruby 1.9 和 Perl (Coro) 都支持,还有什么?任何有成熟的GC和动态方法调用就足够了。

I'd like to start a new network server project in a language that supports concurrency through fibers aka coroutines aka user-mode threads. Determining what exactly are my options has been exceedingly difficult as the term "coroutine" seems to be used quite loosely to mean a variety of things, and "fiber" is used almost exclusively in reference to the Win32 API.

For the purposes of this question, coroutines/fibers:

  • support methods that pause execution by yielding a result to the calling function from within a nested function (i.e. arbitrarily deep in the call stack from where the coroutine/fiber was invoked)
  • support transferring control to another arbitrary coroutine at its current point of execution (i.e. yield to a coroutine that did not call your coroutine)

What are my language options? I know Ruby 1.9 and Perl (Coro) both have support, what else? Anything with a mature gc and dynamic method invocation is sufficient.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

末蓝 2024-08-22 16:52:06

greenlet 扩展满足您在 Python 中的要求(常规扩展,而不是 Stackless)。

Greenlet API 有点低级,因此我建议使用 gevent ,它为您提供适合应用程序的 API。 (免责声明:我写了 gevent)

greenlet extension meets your requirements in Python (regular one, not Stackless).

Greenlet API is a bit low-level, so I recommend using gevent that gives you API suitable for an application. (Disclaimer: I wrote gevent)

歌入人心 2024-08-22 16:52:06

Lua支持协程,参见 http://lua-users.org/wiki/CoroutinesTutorial ,给出尝试一下吧!

Lua supports coroutines, see http://lua-users.org/wiki/CoroutinesTutorial , give it a try!

2024-08-22 16:52:06

目前处于测试阶段的 Tcl 8.6 将支持协程。有关详细信息,请参阅Tcl Wiki 协程页面

Tcl 8.6, currently in beta, will support coroutines. For more info see the Tcl Wiki coroutine page

音栖息无 2024-08-22 16:52:06

Stackless Python 是另一个满足您要求的选项。如果 Python、Ruby 和 Perl 都不适合您的目的(尽管都满足您规定的要求),那么您可能还有其他未说明的要求或偏好 - 愿意将它们拼写出来吗?-)

Stackless Python is another option that meets your requirements. If Python, Ruby and Perl are all unsuitable for your purposes (despite all meeting your stated requirements), you presumably have other unstated requirements or preferences -- care to spell them out?-)

青春有你 2024-08-22 16:52:06

方案有call-with-current-continuation,它是可以构建各种流控制的构建块。它绝对可以支持你提到的两种用途。

方案有许多强大且广泛可用的实现,例如 PLT 方案鸡计划

Scheme has call-with-current-continuation which is a building block on which all kinds of flow control can be built. It definitely can support the two uses you mentioned.

There are many robust, widely available implementations of Scheme such as PLT Scheme and Chicken Scheme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文