fix(phase2): llc 并行线程数组修复 list 元素间距与容量越界
1b5246f 引入 list[Thread] 时误把 max_threads 当作 list 构造的
容量参数传入,实际第二参数是 elem_size=16 → 槽间距 16 字节远小于
Thread 结构体大小,set(j, th) 元素重叠覆盖(get 返回混合垃圾对象);
且 list 初始容量仅 8,batch>8 时 set(8..15) 无容量检查越界写堆 →
llc 全部成功后随机 ACCESS_VIOLATION(ClassArrayTest 崩溃根因,ASAN
构建下更早触发)。改为不传 elem_size(默认取 T.__sizeof__())+
append 自动扩容(8→16→32 覆盖 LLC_MAX_THREADS=16 批量)。
This commit is contained in:
1 parent
42aa90c1af
commit
4bd254a27f
1 file changed
+7
-2
@@ -599,7 +599,12 @@ def run_llc_parallel(tasks: bytes, task_count: int, max_threads: int) -> int:
|
||||
# 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)
|
||||
# 注意:list[T](pool, N) 第二参数是 elem_size(元素大小)不是容量!
|
||||
# 此前传 max_threads=16 → 槽间距 16 字节 < Thread 结构体大小,set 时
|
||||
# 元素重叠覆盖(get 返回混合垃圾),且初始容量仅 8,set(8..15) 越界写
|
||||
# 破坏堆 → llc 成功后随机 ACCESS_VIOLATION。改为不传 elem_size(默认
|
||||
# T.__sizeof__())+ append 自动扩容(初始 8 → 16 → 32,覆盖最大批量)。
|
||||
th_list: list[vthreading.Thread] | t.CPtr = list[vthreading.Thread](_mbuddy)
|
||||
if th_list is None:
|
||||
VLogger.error("run_llc_parallel: 线程数组分配失败", "PhaseB")
|
||||
return 1
|
||||
@@ -617,7 +622,7 @@ 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()
|
||||
th_list.set(j, th)
|
||||
th_list.append(th)
|
||||
j += 1
|
||||
# 本批 join
|
||||
j = 0
|
||||
|
||||
Reference in new issue
Block a user