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