#[derive(Debug)] struct Node<T> { data: T, next: Mutex<*mut Node<T>>, } #[derive(Debug)] pub struct List<T> { head: Mutex<*mut Node<T>>, } every node in this List is Box::into_rawed. I encountered an invalid memory reference error message while concurrently calling this function.
fn remove(&self, key: &T) -> bool { let mut head = &self.head; if !self.contains(key) { return false; } while let Ok(mut guard) = head.lock() { if guard.is_null() { return false; } if unsafe { &(**guard).data } == key { let droppable = *guard; *guard = *unsafe { &(**guard).next }.lock().unwrap(); drop(unsafe { Box::from_raw(droppable) }); return true; } head = unsafe { &(**guard).next }; } false } I don't understand what's wrong here....I think I am dropping correctly as well?
2 posts - 2 participants
