Set stack size programmatically on Windows

Viewed 2325

Is it possible in WinAPI to set stack size for the current thread at runtime like setrlimit does on Linux? I mean to increase the reserved stack size for the current thread if it is too small for the current requirements. This is in a library that may be called by threads from other programming languages, so it's not an option to set stack size at compile time.

If not, any ideas about a solution like an assembly trampoline that changes the stack pointer to a dynamically allocated memory block?

FAQ: Proxy thread is a surefire solution (unless the caller thread has extremely small stack). However, thread switching seems a performance killer. I need substantial amount of stack for recursion or for _alloca. This is also for performance, because heap allocation is slow, especially if multiple threads allocate from heap in parallel (they get blocked by the same libc/CRT mutex, so the code becomes serial).

2 Answers
Related