Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

rust - How to unlock a rwlock without dropping the lock

How to unlock a rwlock? I can't drop the lock since i need it more than 1 time. I have some code like this:

struct Abc {
    lock: RwLock<()>,
    data: usize,
}

let a = Abc {
    RwLock::new(()),
    data: 0,
};

a.lock.read().unwrap();
// do something with data
// now i need to unlock a.lock so others threads can use it

question from:https://stackoverflow.com/questions/65912586/how-to-unlock-a-rwlock-without-dropping-the-lock

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As @Michael Anderson said, the RwLock is unlocked when the guards is dropped, not the RwLock itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...