# std: add Thread.Condition.timedWait \(\#11352\) · gitcafe/zig

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

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

Visibility: public

Requested revision: 531d5b213f5cc7450c56bea3fc2050dda5794067

Requested commit: 531d5b213f5cc7450c56bea3fc2050dda5794067

Commit: 531d5b213f5cc7450c56bea3fc2050dda5794067

Tree: ba2ab7d1e4362d3642dab55ec9c05a7c7fccbdf0

Author: cryptocode

Committer: GitHub

## Message

```
std: add Thread.Condition.timedWait (#11352)

* std: add Thread.Condition.timedWait

I needed the equivalent of `std::condition_variable::wait_for`, but it's missing in std.
This PR adds an implementation, following the status quo of using std.os.CLOCK.REALTIME in the pthread case (i.e. Futex)

A follow-up patch moving futex/condition stuff to monotonic clocks where available seems like a good idea.
This would involve conditionally exposing more functions and constants through std.c and std.os.
For instance, Chromium picks `pthread_cond_timedwait_relative_np` on macOS and `clock_gettime(CLOCK_MONOTONIC...)` on BSD's.

Tested on Windows 11, macOS 12.2.1 and Linux (with/without libc)

* Sleep in the single threaded case, handle timeout overflow in the Windows case and address a race condition in the AtomicCondition case.
```

## Parents

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

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