On Tue, Aug 04, 2009 at 04:15:35PM +0400, Pavel Shevaev wrote:
Guys, I'm playing around with Boost.Coroutine experimental package[1] and it looks like it's corrupting the stack.
I can't say for sure if it's a stack corruption, however, my application produces a seg.fault when running acceptance tests and gdb can't fully show the core dump backtrace saying "Backtrace stopped: previous frame inner to this frame (corrupt stack?)".
If there are any coroutine users around, could you please give any tips on proper usage of this package, its limitations, etc? I had really high hopes for this package and really don't want to go back to the ugly non-coroutine logic.
In C and C++, each coroutine (and thread for that matter) must have a single, contiguous stack which, in addition, cannot grow. Because of this, you should 1) avoid large local variables (e.g., arrays), 2) avoid recursion of any kind, 3) avoid calling any other functions that use a lot of stack (see 1) and 2)), 4) have enough stack space for signal handling [actually, the best thing to do is to install an alternate signal stack by using sigaltstack()]. If you're running in 64-bit mode, try setting the stack size of each coroutine to something like 1MB; the system's demand-paging logic will actually allocate as much physical memory as the program needs. But the fundamental limitations listed above remain.