Skip to content

Unix Rwlock write_contended code issue #97162

Closed
@Warrenren

Description

@Warrenren

I have review the following code for a lot times:
the code position: /library/std/src/sys/unix/locks/futex_rwlock.rs : line 212

    fn write_contended(&self) {
            ...
            ...
            
            let s = self.state.load(Relaxed);
            // I guess "is_unlocked(state)" should be "is_unlocked(s)"
           // because here "state" should be locked 
          //  and the code should  test "s" for the current status
            if is_unlocked(state) || !has_writers_waiting(s) {
                state = s;
                continue;
            }

            ...
            ...
    }

the code should test the current "self.state" again to avoid unlock write. but "state" is old and is tested. I can not get what it does.

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (52ca603da 2022-04-12)
binary: rustc
commit-hash: 52ca603da73ae9eaddf96f77953b33ad8c47cc8e
commit-date: 2022-04-12
host: x86_64-pc-windows-msvc
release: 1.62.0-nightly
LLVM version: 14.0.0
Backtrace

<backtrace>

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions