struct LockByName<'a> {
name: &'static str,
lok: Arc<Mutex<()>>,
guard: MutexGuard<'a, ()>
}
// ...
let guard = lok.clone().lock().unwrap(); // locks here
LockByName { lok, name, guard } // item for drop
This looks like a self-referential struct, which will definitely cause problems. You have to store the MutexGuard separately from the Mutex.