Boost logo

Boost Users :

Subject: Re: [Boost-users] [coroutine] Stack corruption?
From: Pavel Shevaev (pacha.shevaev_at_[hidden])
Date: 2009-08-06 01:25:56


> 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()].

Thanks a lot for these tips!

> 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.

I migrated to boost.fibers for now and increased the size of the
default stack to 64kb and corruption was gone. I tried to increase the
amount of stack size for boost.coroutine as well but for some reason
it didn't work. I'm going to find out what was wrong with
boost.coroutine since it's faster than boost.fibers thanks to lighter
implementation of stack switching.

-- 
Best regards, Pavel

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net