• Austin Clements's avatar
    runtime: make it possible to exit Go-created threads · eff2b262
    Austin Clements authored
    Currently, threads created by the runtime exist until the whole
    program exits. For #14592 and #20395, we want to be able to exit and
    clean up threads created by the runtime. This commit implements that
    mechanism.
    
    The main difficulty is how to clean up the g0 stack. In cgo mode and
    on Solaris and Windows where the OS manages thread stacks, we simply
    arrange to return from mstart and let the system clean up the thread.
    If the runtime allocated the g0 stack, then we use a new exitThread
    syscall wrapper that arranges to clear a flag in the M once the stack
    can safely be reaped and call the thread termination syscall.
    
    exitThread is based on the existing exit1 wrapper, which was always
    meant to terminate the calling thread. However, exit1 has never been
    used since it was introduced 9 years ago, so it was broken on several
    platforms. exitThread also has the additional complication of having
    to flag that the stack is unused, which requires some tricks on
    platforms that use the stack for syscalls.
    
    This still leaves the problem of how to reap the unused g0 stacks. For
    this, we move the M from allm to a new freem list as part of the M
    exiting. Later, allocm scans the freem list, finds Ms that are marked
    as done with their stack, removes these from the list and frees their
    g0 stacks. This also allows these Ms to be garbage collected.
    
    This CL does not yet use any of this functionality. Follow-up CLs
    will. Likewise, there are no new tests in this CL because we'll need
    follow-up functionality to test it.
    
    Change-Id: Ic851ee74227b6d39c6fc1219fc71b45d3004bc63
    Reviewed-on: https://go-review.googlesource.com/46037
    Run-TryBot: Austin Clements <austin@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    eff2b262
Name
Last commit
Last update
..
asm_386.s Loading commit data...
asm_amd64.s Loading commit data...
asm_arm.s Loading commit data...
asm_arm64.s Loading commit data...
asm_mips64x.s Loading commit data...
asm_mipsx.s Loading commit data...
asm_nacl_amd64p32.s Loading commit data...
asm_ppc64x.s Loading commit data...
asm_s390x.s Loading commit data...
callbacks.go Loading commit data...
callbacks_traceback.go Loading commit data...
cgo.go Loading commit data...
dragonfly.go Loading commit data...
freebsd.go Loading commit data...
gcc_386.S Loading commit data...
gcc_amd64.S Loading commit data...
gcc_android.c Loading commit data...
gcc_android_386.c Loading commit data...
gcc_android_amd64.c Loading commit data...
gcc_android_arm.c Loading commit data...
gcc_android_arm64.c Loading commit data...
gcc_arm.S Loading commit data...
gcc_arm64.S Loading commit data...
gcc_context.c Loading commit data...
gcc_darwin_386.c Loading commit data...
gcc_darwin_amd64.c Loading commit data...
gcc_darwin_arm.c Loading commit data...
gcc_darwin_arm64.c Loading commit data...
gcc_dragonfly_amd64.c Loading commit data...
gcc_fatalf.c Loading commit data...
gcc_freebsd_386.c Loading commit data...
gcc_freebsd_amd64.c Loading commit data...
gcc_freebsd_arm.c Loading commit data...
gcc_libinit.c Loading commit data...
gcc_libinit_windows.c Loading commit data...
gcc_linux_386.c Loading commit data...
gcc_linux_amd64.c Loading commit data...
gcc_linux_arm.c Loading commit data...
gcc_linux_arm64.c Loading commit data...
gcc_linux_mips64x.c Loading commit data...
gcc_linux_mipsx.c Loading commit data...
gcc_linux_ppc64x.c Loading commit data...
gcc_linux_s390x.c Loading commit data...
gcc_mips64x.S Loading commit data...
gcc_mipsx.S Loading commit data...
gcc_mmap.c Loading commit data...
gcc_netbsd_386.c Loading commit data...
gcc_netbsd_amd64.c Loading commit data...
gcc_netbsd_arm.c Loading commit data...
gcc_openbsd_386.c Loading commit data...
gcc_openbsd_amd64.c Loading commit data...
gcc_ppc64x.S Loading commit data...
gcc_s390x.S Loading commit data...
gcc_setenv.c Loading commit data...
gcc_sigaction.c Loading commit data...
gcc_signal2_darwin_armx.c Loading commit data...
gcc_signal_darwin_armx.c Loading commit data...
gcc_signal_darwin_lldb.c Loading commit data...
gcc_solaris_amd64.c Loading commit data...
gcc_traceback.c Loading commit data...
gcc_util.c Loading commit data...
gcc_windows_386.c Loading commit data...
gcc_windows_amd64.c Loading commit data...
iscgo.go Loading commit data...
libcgo.h Loading commit data...
libcgo_unix.h Loading commit data...
mmap.go Loading commit data...
netbsd.go Loading commit data...
openbsd.go Loading commit data...
setenv.go Loading commit data...
sigaction.go Loading commit data...
signal_darwin_arm.s Loading commit data...
signal_darwin_arm64.s Loading commit data...
signal_darwin_armx.go Loading commit data...