Is it possible to create 2 Ruby's Fibers that call each other forever? Would Ruby eventually crash with the stack overflow or do the Fibers not consume stack space?
Asked
Active
Viewed 333 times
2
-
FWIW Ruby fibers have a 4k stack limit. There was recently some discussion on Github, regarding fibers on Rails: https://github.com/rails/rails/issues/2153#issuecomment-2109630 – dwhalen Sep 16 '11 at 19:54
-
+1 for getting stack overflow into the question :) – ian May 25 '13 at 01:12
2 Answers
1
Resuming a fiber doesn't increase the stack size. If you recursed into a function each time before your resumed the other fiber, then the stack would increase until overflow - just as it does with infinite recursion normally.

Steve Dekorte
- 79
- 1
- 4
1
If you write an infinite loop in any programming language, something will eventually break. I'm not familiar with Ruby Fibers, but if they are calling each other via methods, then the stack will overflow eventually.
Other things that can break in an infinite loop scenario are anything that is a limited resource, so disk space and network bandwidth are usually the next two (the network because things usually time out).

cdeszaq
- 30,869
- 25
- 117
- 173
-
2Infinte loop and infinite recursive calls are different. You are not clear about this distinction. Infinite resursive calls will eventually cause stack overflow, but infinite loop is regularly used without any problems such as in the main loop of a GUI application. – sawa May 25 '13 at 00:49