Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to upgrade a upgradable read lock twice in a scope #392

Closed
ling7334 opened this issue Jun 27, 2023 · 0 comments · Fixed by #393
Closed

Fail to upgrade a upgradable read lock twice in a scope #392

ling7334 opened this issue Jun 27, 2023 · 0 comments · Fixed by #393

Comments

@ling7334
Copy link

ling7334 commented Jun 27, 2023

Enviroument

>>Get-ComputerInfo

WindowsBuildLabEx                                       : 22621.1.amd64fre.ni_release.220506-1250
WindowsCurrentVersion                                   : 6.3
WindowsEditionId                                        : Professional
WindowsInstallationType                                 : Client
WindowsProductName                                      : Windows 10 Pro
WindowsVersion                                          : 2009
OSDisplayVersion                                        : 22H2

>> cargo --version
cargo 1.69.0 (6e9a83356 2023-04-12)
#Cargo.toml
[package]
name = "singleflight"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
parking_lot = "0.12"
tracing = { version="0.1", features=["log"] }

[dev-dependencies]
tracing-test = "0.2"

Problem

Try to call with_upgraded of RwLockUpgradableReadGuard twice in a single scope, but stuck on trying to aquire the lock on the second call. Example on rust playground

Here is a minimal problem reproduce

use parking_lot::RwLock;
struct Lock(RwLock<i32>);
fn main() {
    let lock = Lock(RwLock::new(0));
    let mut rl = lock.0.upgradable_read();
    rl.with_upgraded(|_| {
        println!("lock upgrade");
    });
    rl.with_upgraded(|_| {
        println!("lock upgrade");
    });
}

but success to aquire lock seperately like below

fn test_rwlock() {
    use parking_lot::RwLock;
    struct Lock(RwLock<i32>);
    let lock = Lock(RwLock::new(0));
    let rl = lock.0.read();
    drop(rl);
    let wl = lock.0.write();
    trace!("lock upgrade");
    drop(wl);
    let wl = lock.0.write();
    trace!("lock upgrade");
    drop(wl);
}

Expectation

upgradable read lock rl can be access after with_upgraded was called, or can anyone confirm it is by design.

@ling7334 ling7334 changed the title Fail to upgrade a upgradable read lock twice in a block Fail to upgrade a upgradable read lock twice in a scope Jun 27, 2023
Amanieu added a commit that referenced this issue Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant