This patch changes the Go library to multiplex goroutines onto operating system threads. Previously, each new goroutine ran in a separate thread. That is inefficient for programs with lots of goroutines. This patch changes the library such that it runs a certain numbers of threads, and lets each thread switch between goroutines. This is how the master Go library works, and this patch brings in code from the master Go library, adjusted for use by gccgo.
After this it will be appropriate to adjust the channel implementation to use the one in the master Go library, as that one works with the scheduler. The current gccgo channel implementation still uses mutexes and condition variables. It will be more efficient to hook into the scheduler directly. This implementation relies on the functions getcontext, setcontext, and makecontext. If there are systems which don't have those, getcontext and setcontext can be replaced by setjmp and longjmp, but there is no obvious replacement for makecontext. I think that will have to be implemented using processor-specific code, as it needs to set the stack pointer to point to a new stack, and I don't know how to do that in a portable processor-independent manner without using makecontext. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Tested both with and without -fsplit-stack support. Committed to mainline. Ian
foo.patch.bz2
Description: patch