MCPcopy Index your code
hub / github.com/RustPython/RustPython / attach_thread

Function attach_thread

crates/vm/src/vm/thread.rs:153–183  ·  view source on GitHub ↗
(vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

151
152#[cfg(all(unix, feature = "threading"))]
153fn attach_thread(vm: &VirtualMachine) {
154 CURRENT_THREAD_SLOT.with(|slot| {
155 if let Some(s) = slot.borrow().as_ref() {
156 super::stw_trace(format_args!("attach begin"));
157 loop {
158 match s.state.compare_exchange(
159 THREAD_DETACHED,
160 THREAD_ATTACHED,
161 Ordering::AcqRel,
162 Ordering::Relaxed,
163 ) {
164 Ok(_) => {
165 super::stw_trace(format_args!("attach DETACHED->ATTACHED"));
166 break;
167 }
168 Err(THREAD_SUSPENDED) => {
169 // Parked by stop-the-world — wait until released to DETACHED
170 super::stw_trace(format_args!("attach wait-suspended"));
171 let wait_yields = wait_while_suspended(s);
172 vm.state.stop_the_world.add_attach_wait_yields(wait_yields);
173 // Retry CAS
174 }
175 Err(state) => {
176 debug_assert!(false, "unexpected thread state in attach: {state}");
177 break;
178 }
179 }
180 }
181 }
182 });
183}
184
185/// Transition ATTACHED → DETACHED (like `_PyThreadState_Detach`).
186#[cfg(all(unix, feature = "threading"))]

Callers 1

enter_vmFunction · 0.85

Calls 6

stw_traceFunction · 0.85
wait_while_suspendedFunction · 0.85
withMethod · 0.80
as_refMethod · 0.45
borrowMethod · 0.45

Tested by

no test coverage detected