[rust-dev] Stack usage of green tasks

Chandru chandru.in at gmail.com
Wed Jul 9 08:11:23 PDT 2014


Thanks a lot.

After about an hour of searching around, I found the RED_ZONE in stack.rs

--
Chandra Sekar.S


On Wed, Jul 9, 2014 at 8:36 PM, Alex Crichton <alex at crichton.co> wrote:

> By default, each stack is allocated with a "red zone" at the end for
> running code on stack overflow, calling C functions, etc. The current
> size of the red zone is 20K.
>
> Requested stack sizes are always at least 20K, but the 20K is not
> currently added to the stack size. So for your test case when you
> request a 20K stack you're likely getting a ~10 byte stack (explaining
> the overflow), and with a 21K stack you get a 1K stack which the task
> can run in.
>
> On Wed, Jul 9, 2014 at 8:13 AM, Chandru <chandru.in at gmail.com> wrote:
> > Hi,
> >
> > This piece of code,
> >
> > #![feature(phase)]
> > #[phase(plugin)]
> > extern crate green;
> >
> > use std::io::timer;
> > use std::task::TaskBuilder;
> >
> > green_start!(main)
> >
> > fn main() {
> > for _ in range(0, 10000i) {
> > TaskBuilder::new().stack_size(20*1024).spawn(proc() {
> > timer::sleep(20000)
> > });
> > }
> > }
> >
> > fails with,
> >
> > task '<unknown>' has overflowed its stack
> > Illegal instruction (core dumped)
> >
> > Changing the stack size to 21K works. Why does such a trivial task
> overflow
> > 20K of stack?
> >
> > --
> > Chandra Sekar.S
> >
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev at mozilla.org
> > https://mail.mozilla.org/listinfo/rust-dev
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140709/8bdc5647/attachment.html>


More information about the Rust-dev mailing list