2 use crate::cell::RefCell;
5 use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
11 let mut m = Box::pin(ReentrantMutex::new(()));
33 // FIXME: Simplify this if Arc gets an Arc::get_pin_mut.
34 let mut m = Arc::new(ReentrantMutex::new(RefCell::new(0)));
35 Pin::new_unchecked(Arc::get_mut_unchecked(&mut m)).init();
39 let lock = m.as_ref().lock();
40 let child = thread::spawn(move || {
41 let lock = m2.as_ref().lock();
42 assert_eq!(*lock.borrow(), 4950);
45 let lock = m.as_ref().lock();
46 *lock.borrow_mut() += i;
49 child.join().unwrap();
55 // FIXME: Simplify this if Arc gets an Arc::get_pin_mut.
56 let mut m = Arc::new(ReentrantMutex::new(()));
57 Pin::new_unchecked(Arc::get_mut_unchecked(&mut m)).init();
61 let _lock = m.as_ref().try_lock();
62 let _lock2 = m.as_ref().try_lock();
63 thread::spawn(move || {
64 let lock = m2.as_ref().try_lock();
65 assert!(lock.is_none());
69 let _lock3 = m.as_ref().try_lock();
72 pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>);
73 impl Drop for Answer<'_> {
75 *self.0.borrow_mut() = 42;