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

std.Thread.Mutex.Held missing #8246

Closed
pfgithub opened this issue Mar 14, 2021 · 0 comments
Closed

std.Thread.Mutex.Held missing #8246

pfgithub opened this issue Mar 14, 2021 · 0 comments
Labels
standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@pfgithub
Copy link
Contributor

const Mutex = @import("std").Thread.Mutex;
var mutex = Mutex{};
const held: Mutex.Held = mutex.acquire(); // Mutex.Held is missing

This seems to have been forgotten in 9698ea3. I tried to add it myself (#8245) but it causes shadowing errors so either the implementations would have to be moved to a separate file or shadowing rules have to be changed (the current shadow rules will also cause Mutex.zig to no longer compile after functions are made into expressions because tryAcquire and acquire shadow the implementations)

@SpexGuy SpexGuy added the standard library This issue involves writing Zig code for the standard library. label Mar 16, 2021
@Vexu Vexu added this to the 0.8.0 milestone Mar 19, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.8.1, 0.9.1 Aug 31, 2021
@andrewrk andrewrk modified the milestones: 0.9.1, 0.9.0 Nov 10, 2021
nuald pushed a commit to nuald/zig that referenced this issue Nov 13, 2021
This is a breaking change. Before, usage looked like this:

```zig
const held = mutex.acquire();
defer held.release();
```

Now it looks like this:

```zig
mutex.lock();
defer mutex.unlock();
```

The `Held` type was an idea to make mutexes slightly safer by making it
more difficult to forget to release an aquired lock. However, this
ultimately caused more problems than it solved, when any data structures
needed to store a held mutex. Simplify everything by reducing the API
down to the primitives: lock() and unlock().

Closes ziglang#8051
Closes ziglang#8246
Closes ziglang#10105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants