Commit graph

11 commits

Author SHA1 Message Date
Andrew Kelley
dc207da184 std.Thread.Pool: don't hold the job closure while blocking on IPC read 2024-06-30 13:54:02 -07:00
Andrew Kelley
6d3a78b8dd std.Thread.Pool: fix connection
TCP cannot be used with UNIX domain sockets
2024-06-30 13:54:02 -07:00
Andrew Kelley
e51fd6728f new thread pool jobserver integration
std.Thread.Pool: back to spawning all threads in initialization because
it's overall simpler. This scheme requires init to be passed a pointer
to the struct.

std.process.Child: implement integration with thread pool jobserver. The
environment variable is called `JOBSERVERV2`. The API works based on
assigning a thread pool to the child process.

build runner: store the thread pool in std.Build.Graph so that it can be
passed to child processes during the make phase.

Fix not allocating +1 pollfds in previous commit.
2024-06-30 13:54:02 -07:00
Andrew Kelley
c395df25ab std.Thread.Pool: implement jobserverv2 protocol
The host accepts N simultaneous connections and writes 1 byte to them
each. Clients connect and read 1 byte in order to obtain a thread token.

std.Thread.Pool now lazily spawns threads only when the work queue is
non-empty. I think that was a bad idea and will revert it shortly.

There is now a std.zig.initThreadPool wrapper that deals with:
* Resolving a zig cache directory into a UNIX domain socket address.
* Creating the "tmp" directory in .zig-cache but only if the listen
  failed due to ENOENT.
* Deciding to connect to an existing jobserver, or become the host for
  child processes.
2024-06-30 13:54:02 -07:00
Andrew Kelley
a72292513e add std.Thread.Pool.spawnWg
This function accepts a WaitGroup parameter and manages the reference
counting therein. It also is infallible.

The existing `spawn` function is still handy when the job wants to
further schedule more tasks.
2024-05-03 20:58:02 -07:00
GethDW
db96ad4a16 std: fix Thread.Pool.spawn
`@alignCast` was required for args with greater alignment than that of a pointer.
2024-04-19 13:49:06 -07:00
Jacob Young
eb723a4070 Update uses of @fieldParentPtr to use RLS 2024-03-30 20:50:48 -04:00
Jacob Young
e409afb79b Update uses of @fieldParentPtr to pass a pointer type 2024-03-30 20:50:48 -04:00
Littleote
3331c5e7af Free threads in std.Thread.Pool.init only with pool.join
Free the allocated threads in the initialization of a thread pool only with pool.join instead of additionally calling allocator.free causing free to be called twice.

Resolves #18643
2024-01-22 11:24:35 -08:00
Andrew Kelley
cb09470063 zig build: add a -j<N> option for limiting concurrency 2023-03-15 10:48:12 -07:00
Andrew Kelley
5b90fa05a4 extract ThreadPool and WaitGroup from compiler to std lib 2023-03-15 10:48:12 -07:00
Renamed from src/ThreadPool.zig (Browse further)