# Fix for \#13163: DefaultRwLock accumulates write-waiters, eventually fails to write lock \(\#13180\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/71f876295981ecf5dfb8daadc05e7e9c1c7e1cbe)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 71f876295981ecf5dfb8daadc05e7e9c1c7e1cbe

Requested commit: 71f876295981ecf5dfb8daadc05e7e9c1c7e1cbe

Commit: 71f876295981ecf5dfb8daadc05e7e9c1c7e1cbe

Tree: 8ebedc0c5c72fca68c82297bc70dc9247360baa1

Author: jumpnbrownweasel

Committer: GitHub

## Message

```
Fix for #13163: DefaultRwLock accumulates write-waiters, eventually fails to write lock (#13180)

* Fix for: DefaultRwLock accumulates write-waiters, eventually fails to write lock #13163

* Comment out debug.print at the end of the last test.

* Code formatting

* - use equality test after lock/unlock rather than peeking into internals.
  however, this is still implementation specific and only done for
  DefaultRwLock.
- add num_reads maximum to ensure that reader threads stop if writer threads are
  starved
- use relaxed orderings for the read atomic counter
- don't check at the end for non-zero read ops, since the reader threads may
  only run once if they are starved

* More review changes
- Monotonic is sufficient for incrementing the reads counter
```

## Parents

- [ce3ffa5e1b30b3ad5fb38639c7e3036d328a598e](https://git.cafe/gitcafe/zig/commit/ce3ffa5e1b30b3ad5fb38639c7e3036d328a598e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/71f876295981ecf5dfb8daadc05e7e9c1c7e1cbe?format=markdown)
