mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-22 01:48:11 +00:00
- docs/zh/架构迁移评估.md: C ABI→子进程+共享内存完整迁移论证(1621行) - docs/zh/experiments/: 18项可复跑可行性实验(架构评估的所有数字来源) - plan.md §11: 11.1~11.9 插件架构缺陷修复清单(唯一权威编号) - main 保持干净,本批次为 update 特性分支的整改起点
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
//go:build ignore
|
||
|
||
package main
|
||
|
||
/*
|
||
#cgo LDFLAGS: -ldl
|
||
#include <dlfcn.h>
|
||
#include <stdlib.h>
|
||
typedef void (*fn)(void);
|
||
static void call(void* f){ ((fn)f)(); }
|
||
*/
|
||
import "C"
|
||
import (
|
||
"fmt"
|
||
"os"
|
||
"runtime"
|
||
"time"
|
||
"unsafe"
|
||
)
|
||
|
||
func threads() int { e,_ := os.ReadDir("/proc/self/task"); return len(e) }
|
||
|
||
func main() {
|
||
p := C.CString("./hang.so"); h := C.dlopen(p, C.RTLD_NOW); C.free(unsafe.Pointer(p))
|
||
n := C.CString("hang_forever"); f := C.dlsym(h, n); C.free(unsafe.Pointer(n))
|
||
base := threads()
|
||
fmt.Printf("基线 threads=%d goroutines=%d\n\n", base, runtime.NumGoroutine())
|
||
for i := 1; i <= 20; i++ {
|
||
done := make(chan string, 1)
|
||
go func() { C.call(f); done <- "ok" }()
|
||
select {
|
||
case <-done:
|
||
case <-time.After(120 * time.Millisecond):
|
||
}
|
||
if i%5 == 0 {
|
||
fmt.Printf(" %2d 次卡死调用后: goroutines=%2d threads=%2d (+%d)\n",
|
||
i, runtime.NumGoroutine(), threads(), threads()-base)
|
||
}
|
||
}
|
||
fmt.Printf("\n结论: 20 次超时 → 泄漏 %d goroutine, %d OS 线程\n",
|
||
runtime.NumGoroutine()-1, threads()-base)
|
||
fmt.Println("每个卡在 cgo 里的 goroutine 独占一个 M(OS 线程),无法被抢占或回收")
|
||
}
|