写一段rust代码,两个线程共享一个bool变量,一个写,一个读
摘要:use std::sync::{Arc, Mutex}; use std::thread; fn main() { // 创建一个布尔变量并用 Arc 和 Mutex 包装,使其可在多个线程间共享和修改 let shared_bool = Arc::new(Mutex::new(false)); /
阅读全文
posted @ 2024-01-29 10:55