chashmap: using alter and remove may cause deadlock
Created by: archerfeel
This may not be a bug, not like #52. I just want to make a notice : )
// channels -- Arc<CHashMap<String, Channel>>
// ch -- struct Channel { container: Arc<CHashMap<String, Channel>, ...}
channels.alter(some_key, |op_ch| match op_ch {
None => None,
Some(ref ch) => {
// call `close` to remove itself from CHashMap
ch.close();
Some(ch)
}
})
impl Channel {
pub fn close(&self) {
//DEADLOCK here
if let Some(ch) = self.container.remove(&self.id) {
ch.shutdown(Shutdown::Both);
}
}
}
RwLock is not re-entrant
pub fn alter<F>(&self, key: K, f: F)
where F: FnOnce(Option<V>) -> Option<V> {
let lock = self.table.read();
...
}
pub fn remove(&self, key: &K) -> Option<V> {
// Acquire the read lock of the table.
let lock = self.table.read();
...
}