> Ok, if anyone is interested, it seems I found how to limit number of OS
> threads. Not very efficient for small gomaxthreads though, because it drains
> g queue and then puts most of them back in the same order. This patch makes
> it possible to specify GOMAXTHREADS=n to restrict maximum number of OS
> threads, doesn't work with cgo for some reason though. Simple programs work
> with at least GOMAXTHREADS=2. Test suite passes with GOMAXTHREADS=3 (timeout
> in http with GOMAXTHREADS=2). Here's my patch against release:
The general problem with this is that the program can deadlock in some
cases. I'm not saying that you haven't identified a real problem, but
your patch doesn't entirely solve it.
The specific case of connect we could actually handle by putting the
socket into nonblocking mode before calling connect and then extending
the epoll/kqueue code to handle completed connections.
Ian
Given this citation, FreeBSD may need a similar fix. I'll take a look.
--dho
No, freebsd uses different syscalls and arguments are different: is
specifies stack base and stack size explicitly.
However, there might be another bug, in pkg/runtime/proc.c there's a
call runtime·newosproc(m, m->g0, m->g0->stackbase, runtime·mstart),
however freebsd runtime·newosproc uses g->stackbase for stack_base and
stk - g->stackbase for stack size, doesn't it mean it uses 0 as
stack_size (besides the formula looks completely wrong, given that
both newosproc's stk and goroutine's stackbase point closer to stack
end)? Don't know if it matters though...