[英]Does coroutine stacks grow in Lua, Python, Ruby or any other languages?
There are some languages which support deterministic lightweight concurrency - coroutine. 有一些语言支持确定性轻量级并发-协程。
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.