Skip to main content

lock_write

Function lock_write 

Source
pub fn lock_write<T: Send + Sync + 'static>(
    lock: SafeLock<T>,
) -> AsyncOwnedRwLockWriteGuard<T>
Expand description

Obtain write guard to standard spin lock such that you have a more ergonomic interface to locked data.

It is preferable to use process_write_critical_section when you must process critical logic that is sensitive to time of check time of use security bugs!

ยงExample

use rumtk_core::threading::thread_primitives::SafeLock;
use rumtk_core::threading::threading_functions::{new_lock, lock_read, lock_write};

let data = 5;
let lock = new_lock(data.clone());
let new_data = 10;

*lock_write(lock.clone()) = new_data;

let result = *lock_read(lock);

assert_eq!(result, new_data, "Failed to modify the locked data!");