简体   繁体   English

协程堆栈是否以Lua,Python,Ruby或任何其他语言增长?

[英]Does coroutine stacks grow in Lua, Python, Ruby or any other languages?

There are some languages which support deterministic lightweight concurrency - coroutine. 有一些语言支持确定性轻量级并发-协程。

  1. Lua - coroutine Lua-协程
  2. Stack-less Python - tasklet 无堆栈Python-Tasklet
  3. Ruby - fiber 红宝石-纤维
  4. should be many more... but currently I don't have much idea. 应该更多...但是目前我没有太多主意。

Anyway as far as I know, it needs many of separated stacks, so I want to know how these languages handle the stack growth. 无论如何,据我所知,它需要许多分离的堆栈,所以我想知道这些语言如何处理堆栈的增长。 This because I read some mention about Ruby Fiber which comes with 4KB - obviously big overhead - and they are advertising this as a feature that prevents stack overflow. 这是因为我阅读了有关 4KB附带的Ruby Fiber的信息 -显然是很大的开销-并且他们正在宣传此功能,以防止堆栈溢出。 But I don't understand why they're just saying the stacks will grow automatically. 但是我不明白为什么他们只是说堆栈会自动增长。 It doesn't make sense the VM - which is not restricted to C stack - can't handle stack growth, but I can't confirm this because I don't know about internals well. VM-不限于C堆栈-无法处理堆栈增长,这是没有道理的,但是我无法确认这一点,因为我不太了解内部机制。

How do they handle stack growth on these kind of micro-threads? 他们如何处理这类微线程的堆栈增长? Is there any explicit/implicit limitations? 有明确/隐含的限制吗? Or just will be handled clearly and automatically? 还是只是会被清晰,自动地处理?

For ruby: 对于红宝石:

As per this google tech talk the ruby vm uses a slightly hacky system involving having a copy of the C stack for each thread and then copying that stack on to the main stack every time it switches between fibers. 按照这个Google技术的说法 ,ruby vm使用一个稍微有点怪异的系统,涉及为每个线程复制C堆栈,然后每次在光纤之间切换时将该堆栈复制到主堆栈上。 This means that Ruby is still restricts each fibre from having more than a 4KB stack but the interpreter does not overflow if you switch between deeply nested fibres. 这意味着Ruby仍然限制每个光纤的堆栈不能超过4KB,但是如果您在深层嵌套的光纤之间切换,则解释器不会溢出。

For python: 对于python:

task-lets are only available in the stackless variant. task-let仅在无堆栈版本中可用。 Each thread gets its own heap based stack as the stackless python vm uses heap based stacks. 每个线程都有自己的基于堆的堆栈,因为无堆栈的python vm使用基于堆的堆栈。 This mess they are inherently only limited to the size of the heap in stack growth. 这种混乱局面在本质上仅限于堆栈增长中堆的大小。 This means that for 32 bit systems there is still an effective limit of 1-4 GB. 这意味着对于32位系统,仍然有1-4 GB的有效限制。

For Lua: 对于Lua:

Lua uses a heap based stack so are inherently only limited to the size of the heap in stack growth. Lua使用基于堆的堆栈,因此在堆栈增长中本质上仅限于堆的大小。 Each coroutine gets its own stack in the memory. 每个协程在内存中都有其自己的堆栈。 This means that for 32 bit systems there is still an effective limit of 1-4 GB. 这意味着对于32位系统,仍然有1-4 GB的有效限制。

To add a couple more to your list C# and VB.Net both now support async/await. 为了将更多信息添加到列表中,C#和VB.Net现在都支持异步/等待。 This is a system that allows the program to preform a time consuming operation and have the rest of that function continue afterwards. 这是一个允许程序执行耗时的操作并使该功能的其余部分随后继续执行的系统。 This is implemented by creating an object to represent the method with a single method that is called to advance to the next step in the method which is called when you attempt to get a result and various other internal locations. 这是通过创建一个对象来表示的,该对象用一个方法来表示,该方法被调用以前进到方法中的下一个步骤,当您尝试获取结果以及其他各种内部位置时,将调用该方法。 The original method is replaced with one that creates the object. 原始方法替换为创建对象的方法。 This means that the recursion depth is not affected as the method is never more than a few steps further down the stack than you would expect. 这意味着递归深度不会受到影响,因为该方法在堆栈的最下方不会比您期望的多出几步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么这些Ruby方法之一会导致“堆栈溢出”,而另一个却没有呢? (排列算法) - Why does one of these Ruby methods result in 'stack overflow' but the other doesn't? (Permutations Algorithm) Hotspot JVM的“ Xss”选项是否设置了固定的“初始堆栈大小”或堆栈可以增长到的“最大堆栈大小”? - Does the “Xss” option for the Hotspot JVM set the “initial stack size” which is fixed or the “maximum stack size” upto which the stack can grow? 堆栈中的内存冲突 - Memory collision in Stacks 由于递归的任何其他原因,堆栈溢出是否会发生? - Can a stack overflow happen for any other reason that recursion? C++协程导致栈溢出 - C++ coroutine causes stack overflow 母语中的堆栈溢出行为 - Stack Overflow Behaviour in Native Languages 在具有拆分堆栈的多线程应用程序上,使用setrlimit()增加堆栈空间 - Increasing stack space with setrlimit() on a multi-threaded application with split stacks 为什么这种二分搜索实现会导致 Ruby 中的堆栈溢出,但不会导致 Java 中的堆栈溢出? - Why does this binary search implementation cause stack overflow in Ruby but not Java? c++协程连续循环导致堆栈溢出 - c++ coroutine continuous loop causes stack overflow Python 是否优化尾递归? - Does Python optimize tail recursion?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM