小弧光的博客

公众号:小弧光黑板报

导航

2024年1月29日 #

写一段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 小弧光 阅读(48) 评论(0) 推荐(0) 编辑