Skip to content

std.Thread: Mutex and Condition improvements#11497

Merged
kprotty merged 14 commits intoziglang:masterfrom
kprotty:thread-mutex-cond
Apr 24, 2022
Merged

std.Thread: Mutex and Condition improvements#11497
kprotty merged 14 commits intoziglang:masterfrom
kprotty:thread-mutex-cond

Conversation

@kprotty
Copy link
Contributor

@kprotty kprotty commented Apr 22, 2022

Main Goals

  • Optimize Mutex and Condiiton implementations to use Futex based algorithms.
  • More robust tests for Mutex and Condition.
  • More documentation in general, but specifically about Condition semantics.

Side Goals

  • Guarantee at most u64 large sync primitives (if Futex is removed in the future, they can always be made usize large).
  • Introduce std.Thread.Futex.Deadline for accurately waiting on a Futex in a loop with a relative timeout.
    • currently used by Condition's futex impl.
    • will be used by Semaphore and ResetEvent's futex impl.

@kprotty kprotty added the standard library This issue involves writing Zig code for the standard library. label Apr 22, 2022
@andrewrk
Copy link
Member

andrewrk commented Apr 22, 2022

error: <inline asm>:1:12: invalid operand for instruction
        lock btsl (%rax), %eax
                  ^~~~~

Is this a problem with stage2 inline assembly? If so, I can work on this to unblock you asap. However if it's possible to work around this with non-assembly code, you can check for @import("builtin").zig_backend != .stage1 and do the fallback condition. Then I can remove the fallback in favor of the assembly after the stage2 issue is fixed, at my leisure.

@kprotty
Copy link
Contributor Author

kprotty commented Apr 22, 2022

@andrewrk Seems like stage2 either doesn't properly lower the *p/*m constraint or treats the X constraint incorrectly.

Also, the CI also says noalias pointers aren't actually pointers. Is this a stage2 false positive?

Copy link
Contributor

@gracefuu gracefuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I can't really comment on the platform specific implementations, but the FutexImpls seem fine. Also, the Condition tests are quite good and can be reused for Semaphore when the time comes to update those.

Just some really minor typos/comments:

@kprotty kprotty merged commit 963ac60 into ziglang:master Apr 24, 2022
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

Successfully merging this pull request may close these issues.

4 participants