How to use parking_lot crate in Rust synchronization

Use parking_lot by adding version 0.12 to Cargo.toml and importing Mutex or RwLock for efficient thread-safe synchronization.

Use parking_lot primitives like Mutex and RwLock by adding the crate to your dependencies and importing them directly into your scope.

use parking_lot::{Mutex, RwLock};

let mutex = Mutex::new(5);
let guard = mutex.lock();
println!("Value: {}", *guard);

let rwlock = RwLock::new(10);
let read_guard = rwlock.read();
println!("Read: {}", *read_guard);

Add parking_lot = "0.12" to your Cargo.toml dependencies.