Skip to content

larsfroelich/RwLockExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RwLockExample

This project demonstrates correct and incorrect usage of std::sync::RwLock in Rust. It stores a number inside a lock and shows how keeping a read lock while trying to acquire a write lock causes blocking.

See the raw code: here

Try in Rust Playground: here

Usage

Run the example with:

cargo run

The first loop succeeds because the read lock is scoped and released before the write lock is taken. The second loop blocks when a write lock is requested while the read lock is still held.

About

Demo of the lifetime of temporarily held mutex locks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages