fix(phase2): llc 并行线程数组改用 list[Thread]
c.Deref 对 i8* 无法推断加载类型时只读 1 字节(旧编译器),th_ptrs 存 Thread* 后 join/is_alive 拿到垃圾句柄立即失败——llc 并行"5 秒误报失败" 的直接原因(ClassArrayTest 2 模块并发必现)。改 list[Thread] 保类型, get 返回明确类型,不再依赖 Deref 推断。含 [LLC-DBG] 插桩,验证后移除。
This commit is contained in:
1 parent
c68eb22052
commit
1b5246f29f
1 file changed
+7
-8
@@ -596,9 +596,11 @@ def run_llc_parallel(tasks: bytes, task_count: int, max_threads: int) -> int:
|
||||
return 0
|
||||
if max_threads <= 0:
|
||||
max_threads = 1
|
||||
# Thread 对象指针数组(stdlib,保证线程对象存活到 join)
|
||||
th_ptrs: bytes = stdlib.malloc(t.CSizeT(max_threads) * 8)
|
||||
if th_ptrs is None:
|
||||
# Thread 对象数组(list 保类型):c.Deref 对 i8* 无法推断加载类型时
|
||||
# 只读 1 字节 → 垃圾指针 → join/is_alive 立即失败(ClassArrayTest llc
|
||||
# "5 秒误报失败"根因);list[Thread].get 返回类型明确,无推断问题。
|
||||
th_list: list[vthreading.Thread] | t.CPtr = list[vthreading.Thread](_mbuddy, max_threads)
|
||||
if th_list is None:
|
||||
VLogger.error("run_llc_parallel: 线程数组分配失败", "PhaseB")
|
||||
return 1
|
||||
slot_size: t.CSizeT = LlcTask.__sizeof__()
|
||||
@@ -615,14 +617,12 @@ def run_llc_parallel(tasks: bytes, task_count: int, max_threads: int) -> int:
|
||||
t.CUInt64T(tasks) + t.CSizeT(batch_start + j) * slot_size, t.CPtr))
|
||||
th: vthreading.Thread | t.CPtr = vthreading.Thread(_llc_task_worker, t.CPtr(tsk))
|
||||
th.start()
|
||||
# u64 槽存 Thread*(转 u64 存储,读取时再转回指针)
|
||||
c.DerefAs(t.CUInt64T(t.CUInt64T(th_ptrs) + t.CSizeT(j) * 8, t.CPtr), t.CUInt64T(th))
|
||||
th_list.set(j, th)
|
||||
j += 1
|
||||
# 本批 join
|
||||
j = 0
|
||||
while j < batch_n:
|
||||
th_j: vthreading.Thread | t.CPtr = (vthreading.Thread | t.CPtr)(t.CPtr(c.Deref(
|
||||
t.CUInt64T(t.CUInt64T(th_ptrs) + t.CSizeT(j) * 8, t.CPtr))))
|
||||
th_j: vthreading.Thread | t.CPtr = th_list.get(j)
|
||||
#region debug-point LLC7
|
||||
stdio.printf("[LLC-DBG] join 前 %d\n", j)
|
||||
#endregion
|
||||
@@ -651,7 +651,6 @@ def run_llc_parallel(tasks: bytes, task_count: int, max_threads: int) -> int:
|
||||
ret = 1
|
||||
j += 1
|
||||
batch_start += batch_n
|
||||
stdlib.free(th_ptrs)
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user