mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix busy interpreter test readiness race (#9328)
Publish readiness only after the main interpreter has completed its first operation, and bound the detached subinterpreter readiness wait. Preserve the original progress assertions, main deadline, and safepoint. AI assistance covered diagnosis, source changes, review, and focused validation. Assisted-by: OpenAI Codex:model-version-unavailable
This commit is contained in:
1 parent
3b9a9f4a4c
commit
0dc77faaab
1 file changed
+10
-1
@@ -1389,7 +1389,6 @@ mod tests {
|
||||
let thread_vm = vm.new_thread();
|
||||
std::thread::spawn(move || {
|
||||
thread_vm.run(|vm| {
|
||||
main_started_worker.store(true, Ordering::Release);
|
||||
let deadline = Instant::now() + Duration::from_secs(30);
|
||||
let mut operations = 0;
|
||||
while !sub_finished_worker.load(Ordering::Acquire) && Instant::now() < deadline
|
||||
@@ -1399,6 +1398,11 @@ mod tests {
|
||||
let result = vm._add(&a, &b).unwrap();
|
||||
assert_eq!(*int::get_value(&result), 42_i32.to_bigint().unwrap());
|
||||
operations += 1;
|
||||
if operations == 1 {
|
||||
// Publish readiness only after actual progress. Otherwise
|
||||
// the sub can finish before this loop's first iteration.
|
||||
main_started_worker.store(true, Ordering::Release);
|
||||
}
|
||||
// The protocol calls above never reach a safepoint on
|
||||
// their own; a bytecode loop would. Without this, a
|
||||
// concurrent stop-the-world could not finish while this
|
||||
@@ -1416,7 +1420,12 @@ mod tests {
|
||||
let sub_worker = sub.enter(|vm| {
|
||||
let thread_vm = vm.new_thread();
|
||||
std::thread::spawn(move || {
|
||||
let deadline = Instant::now() + Duration::from_secs(30);
|
||||
while !main_started_worker.load(Ordering::Acquire) {
|
||||
assert!(
|
||||
Instant::now() < deadline,
|
||||
"main interpreter made no progress before the readiness deadline"
|
||||
);
|
||||
std::thread::yield_now();
|
||||
}
|
||||
thread_vm.run(|vm| {
|
||||
|
||||
Reference in new issue
Block a user