# std.Io.Threaded: hugely improve Windows and NetBSD support · gitcafe/zig

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

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

Visibility: public

Requested revision: e57c557ad41188f85984cb8e6b79c8432cb95ec2

Requested commit: e57c557ad41188f85984cb8e6b79c8432cb95ec2

Commit: e57c557ad41188f85984cb8e6b79c8432cb95ec2

Tree: b14249ce9c6622855640aea8d4c7f2ff2437b1ae

Author: Matthew Lugg

Committer: Matthew Lugg

## Message

```
std.Io.Threaded: hugely improve Windows and NetBSD support

The most interesting thing here is the replacement of the pthread futex
implementation with an implementation based on thread park/unpark APIs.
Thread parking tends to be the primitive provided by systems which do
not have a futex primitive, such as NetBSD, so this implementation is
far more efficient than the pthread one. It is also useful on Windows,
where `RtlWaitOnAddress` is itself a userland implementation based on
thread park/unpark; we can implement it ourselves including support for
features which Windows' implementation lacks, such as cancelation and
waking a number of waiters with 1<n<infinity.

Compared to the pthread implementation, this thread-parking-based one
also supports full robust cancelation. Thread parking also turns out to
be useful for implementing `sleep`, so is now used for that on Windows
and NetBSD.

This commit also introduces proper cancelation support for most Windows
operations. The most notable omission right now is DNS lookups through
`GetAddrInfoEx`, just because they're a little more work due to having
a unique cancelation mechanism---but the machinery is all there, so I'll
finish gluing it together soon.

As of this commit, there are very few parts of `Io.Threaded` which do
not support full robust cancelation. The only ones which actually really
matter (because they could block for a prolonged period of time) are DNS
lookups on Windows (as discussed above) and futex waits on WASM.

```

## Parents

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

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