v0.11.0-alpha.11 63002e0

threadentry_test.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3
4// 386/arm are excluded: the standalone fakecgo test binary resolves pthread
5// from libpthread.so.0, which fails the dynamic symbol lookup on 32-bit linux.
6//go:build !cgo && (linux || darwin || freebsd || netbsd) && !386 && !arm
7
8package fakecgo
9
10import (
11	"runtime"
12	"sync"
13	"testing"
14)
15
16// TestThreadEntryReturn exercises the fakecgo threadentry -> runtime.mstart
17// return path, i.e. that an M created by fakecgo can exit cleanly.
18//
19// When iscgo is forced true by fakecgo, the runtime creates every new OS
20// thread through _cgo_thread_start -> threadentry_trampoline -> threadentry,
21// which calls runtime.mstart. For a fakecgo thread the M's stack is
22// system-allocated, so when the M exits, mexit(osStack=true) returns from
23// mstart back into threadentry. This return path has been the source of
24// crashes (a frame-pointer LEAVE fault on amd64, a bad indirect call and race
25// instrumentation on other platforms), so it is worth exercising everywhere.
26//
27// Locking an OS thread and then letting the goroutine exit (without calling
28// UnlockOSThread) forces the locked fakecgo M to exit, driving mstart to return
29// into threadentry. A busy loop that never lets the goroutine exit does NOT
30// reproduce the crash, because the M never exits and mstart never returns.
31func TestThreadEntryReturn(t *testing.T) {
32	// The M exits on the first goroutine return, so a modest amount of churn is
33	// enough to catch a broken teardown while staying quick under emulation.
34	const rounds = 10
35	const workers = 16
36	for range rounds {
37		var wg sync.WaitGroup
38		wg.Add(workers)
39		for range workers {
40			go func() {
41				defer wg.Done()
42				runtime.LockOSThread()
43				// Intentionally do NOT call UnlockOSThread: returning here exits
44				// the goroutine while its OS thread is locked, forcing the M to
45				// exit and mstart to return into fakecgo.threadentry.
46			}()
47		}
48		wg.Wait()
49	}
50}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close