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.Condition: error: no member named 'unlock' in struct 'std.Thread.Mutex' #8051

Closed
johnLate opened this issue Feb 22, 2021 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@johnLate
Copy link
Contributor

Compiling

const std = @import("std");
pub fn main() !void {
    var mutex = std.Thread.Mutex{};
    var condition = std.Thread.Condition{};
    condition.wait(&mutex);
}

with zig build-exe bug_m.zig results in

/prefix/lib/zig/std/Thread/Condition.zig:154:14: error: no member named 'unlock' in struct 'std.Thread.Mutex'
        mutex.unlock();
             ^

This is in AtomicCondition, pub fn wait(cond: *AtomicCondition, mutex: *Mutex) void.

Note: PthreadCondition is not affected. (zig build-exe -lpthread bug_m.zig)

System information:

zig version                    | 0.8.0-dev.1158+0aef1faa8
git log -n 1 --format='%h %ci' | 0aef1faa8 2021-02-22 00:22:46 +0200
uname -m -o                    | x86_64 GNU/Linux
@SpexGuy SpexGuy added bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library. labels Mar 16, 2021
@Vexu Vexu added this to the 0.8.0 milestone Mar 19, 2021
cescude added a commit to cescude/zig that referenced this issue Apr 17, 2021
This also changes the `wait(...)` signature to take a `Mutex.Impl.Held`
object instead of a plain `Mutex`, which IIUC is clearer to the intent
of the function (ie., you should be passing in a locked mutex, not just
any mutex).

For example:

    var mutex = Mutex{};
    var cond = Condition{};

    var held = mutex.acquire();
    defer held.release();

    while (bad_state == true) {
        // cond.wait(&mutex); // <-- Original
        cond.wait(&held);     // <-- Updated
    }

Not really a breaking change for code using `AtomicCondition` (since it
didn't compile before), but this does affect the other implementations
and would presumably break anything using that code as well.
@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
kprotty pushed a commit to kprotty/zig that referenced this issue Jun 11, 2021
This also changes the `wait(...)` signature to take a `Mutex.Impl.Held`
object instead of a plain `Mutex`, which IIUC is clearer to the intent
of the function (ie., you should be passing in a locked mutex, not just
any mutex).

For example:

    var mutex = Mutex{};
    var cond = Condition{};

    var held = mutex.acquire();
    defer held.release();

    while (bad_state == true) {
        // cond.wait(&mutex); // <-- Original
        cond.wait(&held);     // <-- Updated
    }

Not really a breaking change for code using `AtomicCondition` (since it
didn't compile before), but this does affect the other implementations
and would presumably break anything using that code as well.
@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
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants