Actually, there is a POSIX-compliant way to create a new stack.
The GNU pthreads package use this and it's an interesting read.
However, many existing thread packages use the stack pointer to
identify which thread is currently running, which means that it
is impossible for software that creates it's own stack to co-
exist with these thread packages.
This was all discovered while trying to make Pike dynamically allocate
more C stack. There is even a libc call for doing this on some
platforms, but unless the thread package is aware of what is
going on it crashes horribly when you run that call in a threaded
application.
When it comes right down to it, it's better (and easier) to
implement a better pthreads package then to implement green
threads into Pike.
/ Fredrik (Naranek) Hubinette (Real Build Master)
Previous text:
>2002-08-29 15:06:
>Subject: Green threads
>--------------------------------------------------------------------
>I'm actually not that deep into the intricacies of thread
>implementations either, but afaik there's no reasonably standard way
>to create a new C stack without getting a new OS level thread at the
>same time. Also, longjmp() is only defined to be able to jump to some
>state "higher up" in the same stack and not between different stacks.
>
>Many times it'd probably work to allocate a slab of memory with
>malloc() and then use a bit of implementation-dependent magic to set
>up a jmp_buf struct that points to it, and then start using longjmp()
>and setjmp() to switch between the stacks. It's just a "small matter
>of programming" to get that working on all the different platforms.
>
>Libraries for this probably exists already. It'd be very appreciated
>if someone set out to find one and verify that it works well on all
>the platforms Pike supports.
>
> / Martin Stjernholm, Roxen IS
>