stackrustos-agnostic

How to increase the stack size available to a Rust library?


I am playing with lambda calculus and would like to have a bit more stack space to be able to build and compute (very) long function chains. Is there a way to increase it for the crate, similar to increasing the recursion limit (#![recursion_limit = "100"])?

The crate is a library and I would like it to be able to perform stack-intensive operations regardless of the target operating system.


Solution

  • After some research I concluded that there isn't a universal way to achieve what I am after, but using std::thread::Builder I was able to create an extra thread with a specified stack size and perform stack-heavy operations inside it:

    fn huge_reduction() {
        let builder = thread::Builder::new()
                      .name("reductor".into())
                      .stack_size(32 * 1024 * 1024); // 32MB of stack space
    
        let handler = builder.spawn(|| {
            // stack-intensive operations
        }).unwrap();
    
        handler.join().unwrap();
    }