authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-19 21:31:43-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:48:59-05:00
log0a1def7833882249563358f262e2210beb77492a
tree5441edaf05de9ff0d0d2b33f130adbddffdb9fcd
parente16d3d162a85a822e16ae181ecc6ddc507278126

changes to accomodate std.Thread update


16 files changed, 130 insertions(+), 128 deletions(-)

lib/std/Thread/AutoResetEvent.zig+4-4
...@@ -220,9 +220,9 @@ test "basic usage" {...@@ -220,9 +220,9 @@ test "basic usage" {
220 };220 };
221221
222 var context = Context{};222 var context = Context{};
223 const send_thread = try std.Thread.spawn(Context.sender, &context);223 const send_thread = try std.Thread.spawn(.{}, Context.sender, .{&context});
224 const recv_thread = try std.Thread.spawn(Context.receiver, &context);224 const recv_thread = try std.Thread.spawn(.{}, Context.receiver, .{&context});
225225
226 send_thread.wait();226 send_thread.join();
227 recv_thread.wait();227 recv_thread.join();
228}228}
lib/std/Thread/Futex.zig+24-36
...@@ -413,32 +413,27 @@ test "Futex - Signal" {...@@ -413,32 +413,27 @@ test "Futex - Signal" {
413 }413 }
414 }414 }
415415
416 const Thread = struct {416 const start_value = 1;
417 tx: *Self,
418 rx: *Self,
419417
420 const start_value = 1;418 fn runThread(rx: *Self, tx: *Self) void {
421419 var iterations: u32 = start_value;
422 fn run(self: Thread) void {420 while (iterations < 10) : (iterations += 1) {
423 var iterations: u32 = start_value;421 self.rx.recv(iterations);
424 while (iterations < 10) : (iterations += 1) {422 self.tx.send(iterations);
425 self.rx.recv(iterations);
426 self.tx.send(iterations);
427 }
428 }423 }
429 };424 }
430425
431 fn run() !void {426 fn run() !void {
432 var ping = Self{};427 var ping = Self{};
433 var pong = Self{};428 var pong = Self{};
434429
435 const t1 = try std.Thread.spawn(Thread.run, .{ .rx = &ping, .tx = &pong });430 const t1 = try std.Thread.spawn(.{}, runThread, .{ &ping, &pong });
436 defer t1.wait();431 defer t1.join();
437432
438 const t2 = try std.Thread.spawn(Thread.run, .{ .rx = &pong, .tx = &ping });433 const t2 = try std.Thread.spawn(.{}, runThread, .{ &pong, &ping });
439 defer t2.wait();434 defer t2.join();
440435
441 ping.send(Thread.start_value);436 ping.send(start_value);
442 }437 }
443 }).run();438 }).run();
444}439}
...@@ -507,7 +502,7 @@ test "Futex - Chain" {...@@ -507,7 +502,7 @@ test "Futex - Chain" {
507 try (struct {502 try (struct {
508 completed: Signal = .{},503 completed: Signal = .{},
509 threads: [10]struct {504 threads: [10]struct {
510 thread: *std.Thread,505 thread: std.Thread,
511 signal: Signal,506 signal: Signal,
512 } = undefined,507 } = undefined,
513508
...@@ -531,39 +526,32 @@ test "Futex - Chain" {...@@ -531,39 +526,32 @@ test "Futex - Chain" {
531 };526 };
532527
533 const Self = @This();528 const Self = @This();
534 const Chain = struct {
535 self: *Self,
536 index: usize,
537529
538 fn run(chain: Chain) void {530 fn runThread(self: *Self, index: usize) void {
539 const this_signal = &chain.self.threads[chain.index].signal;531 const this_signal = &chain.self.threads[chain.index].signal;
540532
541 var next_signal = &chain.self.completed;533 var next_signal = &chain.self.completed;
542 if (chain.index + 1 < chain.self.threads.len) {534 if (chain.index + 1 < chain.self.threads.len) {
543 next_signal = &chain.self.threads[chain.index + 1].signal;535 next_signal = &chain.self.threads[chain.index + 1].signal;
544 }
545
546 this_signal.wait();
547 next_signal.notify();
548 }536 }
549 };537
538 this_signal.wait();
539 next_signal.notify();
540 }
550541
551 fn run() !void {542 fn run() !void {
552 var self = Self{};543 var self = Self{};
553544
554 for (self.threads) |*entry, index| {545 for (self.threads) |*entry, index| {
555 entry.signal = .{};546 entry.signal = .{};
556 entry.thread = try std.Thread.spawn(Chain.run, .{547 entry.thread = try std.Thread.spawn(.{}, runThread .{&self, index});
557 .self = &self,
558 .index = index,
559 });
560 }548 }
561549
562 self.threads[0].signal.notify();550 self.threads[0].signal.notify();
563 self.completed.wait();551 self.completed.wait();
564552
565 for (self.threads) |entry| {553 for (self.threads) |entry| {
566 entry.thread.wait();554 entry.thread.join();
567 }555 }
568 }556 }
569 }).run();557 }).run();
lib/std/Thread/Mutex.zig+3-3
...@@ -297,12 +297,12 @@ test "basic usage" {...@@ -297,12 +297,12 @@ test "basic usage" {
297 try testing.expect(context.data == TestContext.incr_count);297 try testing.expect(context.data == TestContext.incr_count);
298 } else {298 } else {
299 const thread_count = 10;299 const thread_count = 10;
300 var threads: [thread_count]*std.Thread = undefined;300 var threads: [thread_count]std.Thread = undefined;
301 for (threads) |*t| {301 for (threads) |*t| {
302 t.* = try std.Thread.spawn(worker, &context);302 t.* = try std.Thread.spawn(.{}, worker, .{&context});
303 }303 }
304 for (threads) |t|304 for (threads) |t|
305 t.wait();305 t.join();
306306
307 try testing.expect(context.data == thread_count * TestContext.incr_count);307 try testing.expect(context.data == thread_count * TestContext.incr_count);
308 }308 }
lib/std/Thread/ResetEvent.zig+4-4
...@@ -281,8 +281,8 @@ test "basic usage" {...@@ -281,8 +281,8 @@ test "basic usage" {
281 var context: Context = undefined;281 var context: Context = undefined;
282 try context.init();282 try context.init();
283 defer context.deinit();283 defer context.deinit();
284 const receiver = try std.Thread.spawn(Context.receiver, &context);284 const receiver = try std.Thread.spawn(.{}, Context.receiver, .{&context});
285 defer receiver.wait();285 defer receiver.join();
286 try context.sender();286 try context.sender();
287287
288 if (false) {288 if (false) {
...@@ -290,8 +290,8 @@ test "basic usage" {...@@ -290,8 +290,8 @@ test "basic usage" {
290 // https://github.com/ziglang/zig/issues/7009290 // https://github.com/ziglang/zig/issues/7009
291 var timed = Context.init();291 var timed = Context.init();
292 defer timed.deinit();292 defer timed.deinit();
293 const sleeper = try std.Thread.spawn(Context.sleeper, &timed);293 const sleeper = try std.Thread.spawn(.{}, Context.sleeper, .{&timed});
294 defer sleeper.wait();294 defer sleeper.join();
295 try timed.timedWaiter();295 try timed.timedWaiter();
296 }296 }
297}297}
lib/std/Thread/StaticResetEvent.zig+4-4
...@@ -384,8 +384,8 @@ test "basic usage" {...@@ -384,8 +384,8 @@ test "basic usage" {
384 };384 };
385385
386 var context = Context{};386 var context = Context{};
387 const receiver = try std.Thread.spawn(Context.receiver, &context);387 const receiver = try std.Thread.spawn(.{}, Context.receiver, .{&context});
388 defer receiver.wait();388 defer receiver.join();
389 try context.sender();389 try context.sender();
390390
391 if (false) {391 if (false) {
...@@ -393,8 +393,8 @@ test "basic usage" {...@@ -393,8 +393,8 @@ test "basic usage" {
393 // https://github.com/ziglang/zig/issues/7009393 // https://github.com/ziglang/zig/issues/7009
394 var timed = Context.init();394 var timed = Context.init();
395 defer timed.deinit();395 defer timed.deinit();
396 const sleeper = try std.Thread.spawn(Context.sleeper, &timed);396 const sleeper = try std.Thread.spawn(.{}, Context.sleeper, .{&timed});
397 defer sleeper.wait();397 defer sleeper.join();
398 try timed.timedWaiter();398 try timed.timedWaiter();
399 }399 }
400}400}
lib/std/atomic/queue.zig+6-6
...@@ -214,20 +214,20 @@ test "std.atomic.Queue" {...@@ -214,20 +214,20 @@ test "std.atomic.Queue" {
214 } else {214 } else {
215 try expect(context.queue.isEmpty());215 try expect(context.queue.isEmpty());
216216
217 var putters: [put_thread_count]*std.Thread = undefined;217 var putters: [put_thread_count]std.Thread = undefined;
218 for (putters) |*t| {218 for (putters) |*t| {
219 t.* = try std.Thread.spawn(startPuts, &context);219 t.* = try std.Thread.spawn(.{}, startPuts, .{&context});
220 }220 }
221 var getters: [put_thread_count]*std.Thread = undefined;221 var getters: [put_thread_count]std.Thread = undefined;
222 for (getters) |*t| {222 for (getters) |*t| {
223 t.* = try std.Thread.spawn(startGets, &context);223 t.* = try std.Thread.spawn(.{}, startGets, .{&context});
224 }224 }
225225
226 for (putters) |t|226 for (putters) |t|
227 t.wait();227 t.join();
228 @atomicStore(bool, &context.puts_done, true, .SeqCst);228 @atomicStore(bool, &context.puts_done, true, .SeqCst);
229 for (getters) |t|229 for (getters) |t|
230 t.wait();230 t.join();
231231
232 try expect(context.queue.isEmpty());232 try expect(context.queue.isEmpty());
233 }233 }
lib/std/atomic/stack.zig+6-6
...@@ -121,20 +121,20 @@ test "std.atomic.stack" {...@@ -121,20 +121,20 @@ test "std.atomic.stack" {
121 }121 }
122 }122 }
123 } else {123 } else {
124 var putters: [put_thread_count]*std.Thread = undefined;124 var putters: [put_thread_count]std.Thread = undefined;
125 for (putters) |*t| {125 for (putters) |*t| {
126 t.* = try std.Thread.spawn(startPuts, &context);126 t.* = try std.Thread.spawn(.{}, startPuts, .{&context});
127 }127 }
128 var getters: [put_thread_count]*std.Thread = undefined;128 var getters: [put_thread_count]std.Thread = undefined;
129 for (getters) |*t| {129 for (getters) |*t| {
130 t.* = try std.Thread.spawn(startGets, &context);130 t.* = try std.Thread.spawn(.{}, startGets, .{&context});
131 }131 }
132132
133 for (putters) |t|133 for (putters) |t|
134 t.wait();134 t.join();
135 @atomicStore(bool, &context.puts_done, true, .SeqCst);135 @atomicStore(bool, &context.puts_done, true, .SeqCst);
136 for (getters) |t|136 for (getters) |t|
137 t.wait();137 t.join();
138 }138 }
139139
140 if (context.put_sum != context.get_sum) {140 if (context.put_sum != context.get_sum) {
lib/std/debug.zig+2-2
...@@ -273,8 +273,8 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c...@@ -273,8 +273,8 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
273 if (builtin.single_threaded) {273 if (builtin.single_threaded) {
274 stderr.print("panic: ", .{}) catch os.abort();274 stderr.print("panic: ", .{}) catch os.abort();
275 } else {275 } else {
276 const current_thread_id = std.Thread.getCurrentThreadId();276 const current_thread_id = std.Thread.getCurrentId();
277 stderr.print("thread {d} panic: ", .{current_thread_id}) catch os.abort();277 stderr.print("thread {} panic: ", .{current_thread_id}) catch os.abort();
278 }278 }
279 stderr.print(format ++ "\n", args) catch os.abort();279 stderr.print(format ++ "\n", args) catch os.abort();
280 if (trace) |t| {280 if (trace) |t| {
lib/std/event/loop.zig+15-15
...@@ -21,12 +21,12 @@ pub const Loop = struct {...@@ -21,12 +21,12 @@ pub const Loop = struct {
21 os_data: OsData,21 os_data: OsData,
22 final_resume_node: ResumeNode,22 final_resume_node: ResumeNode,
23 pending_event_count: usize,23 pending_event_count: usize,
24 extra_threads: []*Thread,24 extra_threads: []Thread,
25 /// TODO change this to a pool of configurable number of threads25 /// TODO change this to a pool of configurable number of threads
26 /// and rename it to be not file-system-specific. it will become26 /// and rename it to be not file-system-specific. it will become
27 /// a thread pool for turning non-CPU-bound blocking things into27 /// a thread pool for turning non-CPU-bound blocking things into
28 /// async things. A fallback for any missing OS-specific API.28 /// async things. A fallback for any missing OS-specific API.
29 fs_thread: *Thread,29 fs_thread: Thread,
30 fs_queue: std.atomic.Queue(Request),30 fs_queue: std.atomic.Queue(Request),
31 fs_end_request: Request.Node,31 fs_end_request: Request.Node,
32 fs_thread_wakeup: std.Thread.ResetEvent,32 fs_thread_wakeup: std.Thread.ResetEvent,
...@@ -189,11 +189,11 @@ pub const Loop = struct {...@@ -189,11 +189,11 @@ pub const Loop = struct {
189 errdefer self.deinitOsData();189 errdefer self.deinitOsData();
190190
191 if (!builtin.single_threaded) {191 if (!builtin.single_threaded) {
192 self.fs_thread = try Thread.spawn(posixFsRun, self);192 self.fs_thread = try Thread.spawn(.{}, posixFsRun, .{self});
193 }193 }
194 errdefer if (!builtin.single_threaded) {194 errdefer if (!builtin.single_threaded) {
195 self.posixFsRequest(&self.fs_end_request);195 self.posixFsRequest(&self.fs_end_request);
196 self.fs_thread.wait();196 self.fs_thread.join();
197 };197 };
198198
199 if (!std.builtin.single_threaded)199 if (!std.builtin.single_threaded)
...@@ -264,11 +264,11 @@ pub const Loop = struct {...@@ -264,11 +264,11 @@ pub const Loop = struct {
264 assert(amt == wakeup_bytes.len);264 assert(amt == wakeup_bytes.len);
265 while (extra_thread_index != 0) {265 while (extra_thread_index != 0) {
266 extra_thread_index -= 1;266 extra_thread_index -= 1;
267 self.extra_threads[extra_thread_index].wait();267 self.extra_threads[extra_thread_index].join();
268 }268 }
269 }269 }
270 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {270 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {
271 self.extra_threads[extra_thread_index] = try Thread.spawn(workerRun, self);271 self.extra_threads[extra_thread_index] = try Thread.spawn(.{}, workerRun, .{self});
272 }272 }
273 },273 },
274 .macos, .freebsd, .netbsd, .dragonfly, .openbsd => {274 .macos, .freebsd, .netbsd, .dragonfly, .openbsd => {
...@@ -329,11 +329,11 @@ pub const Loop = struct {...@@ -329,11 +329,11 @@ pub const Loop = struct {
329 _ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable;329 _ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable;
330 while (extra_thread_index != 0) {330 while (extra_thread_index != 0) {
331 extra_thread_index -= 1;331 extra_thread_index -= 1;
332 self.extra_threads[extra_thread_index].wait();332 self.extra_threads[extra_thread_index].join();
333 }333 }
334 }334 }
335 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {335 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {
336 self.extra_threads[extra_thread_index] = try Thread.spawn(workerRun, self);336 self.extra_threads[extra_thread_index] = try Thread.spawn(.{}, workerRun, .{self});
337 }337 }
338 },338 },
339 .windows => {339 .windows => {
...@@ -378,11 +378,11 @@ pub const Loop = struct {...@@ -378,11 +378,11 @@ pub const Loop = struct {
378 }378 }
379 while (extra_thread_index != 0) {379 while (extra_thread_index != 0) {
380 extra_thread_index -= 1;380 extra_thread_index -= 1;
381 self.extra_threads[extra_thread_index].wait();381 self.extra_threads[extra_thread_index].join();
382 }382 }
383 }383 }
384 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {384 while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {
385 self.extra_threads[extra_thread_index] = try Thread.spawn(workerRun, self);385 self.extra_threads[extra_thread_index] = try Thread.spawn(.{}, workerRun, .{self});
386 }386 }
387 },387 },
388 else => {},388 else => {},
...@@ -651,18 +651,18 @@ pub const Loop = struct {...@@ -651,18 +651,18 @@ pub const Loop = struct {
651 .netbsd,651 .netbsd,
652 .dragonfly,652 .dragonfly,
653 .openbsd,653 .openbsd,
654 => self.fs_thread.wait(),654 => self.fs_thread.join(),
655 else => {},655 else => {},
656 }656 }
657 }657 }
658658
659 for (self.extra_threads) |extra_thread| {659 for (self.extra_threads) |extra_thread| {
660 extra_thread.wait();660 extra_thread.join();
661 }661 }
662662
663 @atomicStore(bool, &self.delay_queue.is_running, false, .SeqCst);663 @atomicStore(bool, &self.delay_queue.is_running, false, .SeqCst);
664 self.delay_queue.event.set();664 self.delay_queue.event.set();
665 self.delay_queue.thread.wait();665 self.delay_queue.thread.join();
666 }666 }
667667
668 /// Runs the provided function asynchronously. The function's frame is allocated668 /// Runs the provided function asynchronously. The function's frame is allocated
...@@ -787,7 +787,7 @@ pub const Loop = struct {...@@ -787,7 +787,7 @@ pub const Loop = struct {
787 const DelayQueue = struct {787 const DelayQueue = struct {
788 timer: std.time.Timer,788 timer: std.time.Timer,
789 waiters: Waiters,789 waiters: Waiters,
790 thread: *std.Thread,790 thread: std.Thread,
791 event: std.Thread.AutoResetEvent,791 event: std.Thread.AutoResetEvent,
792 is_running: bool,792 is_running: bool,
793793
...@@ -802,7 +802,7 @@ pub const Loop = struct {...@@ -802,7 +802,7 @@ pub const Loop = struct {
802 .event = std.Thread.AutoResetEvent{},802 .event = std.Thread.AutoResetEvent{},
803 .is_running = true,803 .is_running = true,
804 // Must be last so that it can read the other state, such as `is_running`.804 // Must be last so that it can read the other state, such as `is_running`.
805 .thread = try std.Thread.spawn(DelayQueue.run, self),805 .thread = try std.Thread.spawn(.{}, DelayQueue.run, .{self}),
806 };806 };
807 }807 }
808808
lib/std/fs/test.zig+5-6
...@@ -862,11 +862,10 @@ test "open file with exclusive lock twice, make sure it waits" {...@@ -862,11 +862,10 @@ test "open file with exclusive lock twice, make sure it waits" {
862 errdefer file.close();862 errdefer file.close();
863863
864 const S = struct {864 const S = struct {
865 const C = struct { dir: *fs.Dir, evt: *std.Thread.ResetEvent };865 fn checkFn(dir: *fs.Dir, evt: *std.Thread.ResetEvent) !void {
866 fn checkFn(ctx: C) !void {866 const file1 = try dir.createFile(filename, .{ .lock = .Exclusive });
867 const file1 = try ctx.dir.createFile(filename, .{ .lock = .Exclusive });
868 defer file1.close();867 defer file1.close();
869 ctx.evt.set();868 evt.set();
870 }869 }
871 };870 };
872871
...@@ -874,8 +873,8 @@ test "open file with exclusive lock twice, make sure it waits" {...@@ -874,8 +873,8 @@ test "open file with exclusive lock twice, make sure it waits" {
874 try evt.init();873 try evt.init();
875 defer evt.deinit();874 defer evt.deinit();
876875
877 const t = try std.Thread.spawn(S.checkFn, S.C{ .dir = &tmp.dir, .evt = &evt });876 const t = try std.Thread.spawn(.{}, S.checkFn, .{ &tmp.dir, &evt });
878 defer t.wait();877 defer t.join();
879878
880 const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms;879 const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms;
881 // Make sure we've slept enough.880 // Make sure we've slept enough.
lib/std/net/test.zig+5-5
...@@ -161,8 +161,8 @@ test "listen on a port, send bytes, receive bytes" {...@@ -161,8 +161,8 @@ test "listen on a port, send bytes, receive bytes" {
161 }161 }
162 };162 };
163163
164 const t = try std.Thread.spawn(S.clientFn, server.listen_address);164 const t = try std.Thread.spawn(.{}, S.clientFn, .{server.listen_address});
165 defer t.wait();165 defer t.join();
166166
167 var client = try server.accept();167 var client = try server.accept();
168 defer client.stream.close();168 defer client.stream.close();
...@@ -277,7 +277,7 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -277,7 +277,7 @@ test "listen on a unix socket, send bytes, receive bytes" {
277 try server.listen(socket_addr);277 try server.listen(socket_addr);
278278
279 const S = struct {279 const S = struct {
280 fn clientFn(_: void) !void {280 fn clientFn() !void {
281 const socket = try net.connectUnixSocket(socket_path);281 const socket = try net.connectUnixSocket(socket_path);
282 defer socket.close();282 defer socket.close();
283283
...@@ -285,8 +285,8 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -285,8 +285,8 @@ test "listen on a unix socket, send bytes, receive bytes" {
285 }285 }
286 };286 };
287287
288 const t = try std.Thread.spawn(S.clientFn, {});288 const t = try std.Thread.spawn(.{}, S.clientFn, .{});
289 defer t.wait();289 defer t.join();
290290
291 var client = try server.accept();291 var client = try server.accept();
292 defer client.stream.close();292 defer client.stream.close();
lib/std/once.zig+4-4
...@@ -55,16 +55,16 @@ test "Once executes its function just once" {...@@ -55,16 +55,16 @@ test "Once executes its function just once" {
55 global_once.call();55 global_once.call();
56 global_once.call();56 global_once.call();
57 } else {57 } else {
58 var threads: [10]*std.Thread = undefined;58 var threads: [10]std.Thread = undefined;
59 defer for (threads) |handle| handle.wait();59 defer for (threads) |handle| handle.join();
6060
61 for (threads) |*handle| {61 for (threads) |*handle| {
62 handle.* = try std.Thread.spawn(struct {62 handle.* = try std.Thread.spawn(.{}, struct {
63 fn thread_fn(x: u8) void {63 fn thread_fn(x: u8) void {
64 _ = x;64 _ = x;
65 global_once.call();65 global_once.call();
66 }66 }
67 }.thread_fn, 0);67 }.thread_fn, .{0});
68 }68 }
69 }69 }
7070
lib/std/os/test.zig+17-19
...@@ -320,9 +320,9 @@ test "std.Thread.getCurrentId" {...@@ -320,9 +320,9 @@ test "std.Thread.getCurrentId" {
320 if (builtin.single_threaded) return error.SkipZigTest;320 if (builtin.single_threaded) return error.SkipZigTest;
321321
322 var thread_current_id: Thread.Id = undefined;322 var thread_current_id: Thread.Id = undefined;
323 const thread = try Thread.spawn(testThreadIdFn, &thread_current_id);323 const thread = try Thread.spawn(.{}, testThreadIdFn, .{&thread_current_id});
324 const thread_id = thread.handle();324 const thread_id = thread.getHandle();
325 thread.wait();325 thread.join();
326 if (Thread.use_pthreads) {326 if (Thread.use_pthreads) {
327 try expect(thread_current_id == thread_id);327 try expect(thread_current_id == thread_id);
328 } else if (native_os == .windows) {328 } else if (native_os == .windows) {
...@@ -339,21 +339,20 @@ test "spawn threads" {...@@ -339,21 +339,20 @@ test "spawn threads" {
339339
340 var shared_ctx: i32 = 1;340 var shared_ctx: i32 = 1;
341341
342 const thread1 = try Thread.spawn(start1, {});342 const thread1 = try Thread.spawn(.{}, start1, .{});
343 const thread2 = try Thread.spawn(start2, &shared_ctx);343 const thread2 = try Thread.spawn(.{}, start2, .{&shared_ctx});
344 const thread3 = try Thread.spawn(start2, &shared_ctx);344 const thread3 = try Thread.spawn(.{}, start2, .{&shared_ctx});
345 const thread4 = try Thread.spawn(start2, &shared_ctx);345 const thread4 = try Thread.spawn(.{}, start2, .{&shared_ctx});
346346
347 thread1.wait();347 thread1.join();
348 thread2.wait();348 thread2.join();
349 thread3.wait();349 thread3.join();
350 thread4.wait();350 thread4.join();
351351
352 try expect(shared_ctx == 4);352 try expect(shared_ctx == 4);
353}353}
354354
355fn start1(ctx: void) u8 {355fn start1() u8 {
356 _ = ctx;
357 return 0;356 return 0;
358}357}
359358
...@@ -371,16 +370,15 @@ test "cpu count" {...@@ -371,16 +370,15 @@ test "cpu count" {
371370
372test "thread local storage" {371test "thread local storage" {
373 if (builtin.single_threaded) return error.SkipZigTest;372 if (builtin.single_threaded) return error.SkipZigTest;
374 const thread1 = try Thread.spawn(testTls, {});373 const thread1 = try Thread.spawn(.{}, testTls, .{});
375 const thread2 = try Thread.spawn(testTls, {});374 const thread2 = try Thread.spawn(.{}, testTls, .{});
376 try testTls({});375 try testTls({});
377 thread1.wait();376 thread1.join();
378 thread2.wait();377 thread2.join();
379}378}
380379
381threadlocal var x: i32 = 1234;380threadlocal var x: i32 = 1234;
382fn testTls(context: void) !void {381fn testTls() !void {
383 _ = context;
384 if (x != 1234) return error.TlsBadStartValue;382 if (x != 1234) return error.TlsBadStartValue;
385 x += 1;383 x += 1;
386 if (x != 1235) return error.TlsBadEndValue;384 if (x != 1235) return error.TlsBadEndValue;
lib/std/target.zig+19-4
...@@ -69,6 +69,13 @@ pub const Target = struct {...@@ -69,6 +69,13 @@ pub const Target = struct {
69 };69 };
70 }70 }
7171
72 pub fn isBSD(tag: Tag) bool {
73 return tag.isDarwin() or switch (tag) {
74 .kfreebsd, .freebsd, .openbsd, .netbsd, .dragonfly => true,
75 else => false,
76 };
77 }
78
72 pub fn dynamicLibSuffix(tag: Tag) [:0]const u8 {79 pub fn dynamicLibSuffix(tag: Tag) [:0]const u8 {
73 if (tag.isDarwin()) {80 if (tag.isDarwin()) {
74 return ".dylib";81 return ".dylib";
...@@ -787,6 +794,13 @@ pub const Target = struct {...@@ -787,6 +794,13 @@ pub const Target = struct {
787 };794 };
788 }795 }
789796
797 pub fn isAARCH64(arch: Arch) bool {
798 return switch (arch) {
799 .aarch64, .aarch64_be, .aarch64_32 => true,
800 else => false,
801 };
802 }
803
790 pub fn isThumb(arch: Arch) bool {804 pub fn isThumb(arch: Arch) bool {
791 return switch (arch) {805 return switch (arch) {
792 .thumb, .thumbeb => true,806 .thumb, .thumbeb => true,
...@@ -1365,10 +1379,7 @@ pub const Target = struct {...@@ -1365,10 +1379,7 @@ pub const Target = struct {
1365 }1379 }
13661380
1367 pub fn isAndroid(self: Target) bool {1381 pub fn isAndroid(self: Target) bool {
1368 return switch (self.abi) {1382 return self.abi == .android;
1369 .android => true,
1370 else => false,
1371 };
1372 }1383 }
13731384
1374 pub fn isWasm(self: Target) bool {1385 pub fn isWasm(self: Target) bool {
...@@ -1379,6 +1390,10 @@ pub const Target = struct {...@@ -1379,6 +1390,10 @@ pub const Target = struct {
1379 return self.os.tag.isDarwin();1390 return self.os.tag.isDarwin();
1380 }1391 }
13811392
1393 pub fn isBSD(self: Target) bool {
1394 return self.os.tag.isBSD();
1395 }
1396
1382 pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool {1397 pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool {
1383 return os_tag == .linux and abi.isGnu();1398 return os_tag == .linux and abi.isGnu();
1384 }1399 }
src/ThreadPool.zig+2-2
...@@ -74,13 +74,13 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void {...@@ -74,13 +74,13 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void {
74 try worker.idle_node.data.init();74 try worker.idle_node.data.init();
75 errdefer worker.idle_node.data.deinit();75 errdefer worker.idle_node.data.deinit();
7676
77 worker.thread = try std.Thread.spawn(Worker.run, worker);77 worker.thread = try std.Thread.spawn(.{}, Worker.run, .{worker});
78 }78 }
79}79}
8080
81fn destroyWorkers(self: *ThreadPool, spawned: usize) void {81fn destroyWorkers(self: *ThreadPool, spawned: usize) void {
82 for (self.workers[0..spawned]) |*worker| {82 for (self.workers[0..spawned]) |*worker| {
83 worker.thread.wait();83 worker.thread.join();
84 worker.idle_node.data.deinit();84 worker.idle_node.data.deinit();
85 }85 }
86}86}
tools/update_cpu_features.zig+10-8
...@@ -816,18 +816,20 @@ pub fn main() anyerror!void {...@@ -816,18 +816,20 @@ pub fn main() anyerror!void {
816 });816 });
817 }817 }
818 } else {818 } else {
819 var threads = try arena.alloc(*std.Thread, llvm_targets.len);819 var threads = try arena.alloc(std.Thread, llvm_targets.len);
820 for (llvm_targets) |llvm_target, i| {820 for (llvm_targets) |llvm_target, i| {
821 threads[i] = try std.Thread.spawn(processOneTarget, .{821 threads[i] = try std.Thread.spawn(.{}, processOneTarget, .{
822 .llvm_tblgen_exe = llvm_tblgen_exe,822 Job{
823 .llvm_src_root = llvm_src_root,823 .llvm_tblgen_exe = llvm_tblgen_exe,
824 .zig_src_dir = zig_src_dir,824 .llvm_src_root = llvm_src_root,
825 .root_progress = root_progress,825 .zig_src_dir = zig_src_dir,
826 .llvm_target = llvm_target,826 .root_progress = root_progress,
827 .llvm_target = llvm_target,
828 },
827 });829 });
828 }830 }
829 for (threads) |thread| {831 for (threads) |thread| {
830 thread.wait();832 thread.join();
831 }833 }
832 }834 }
833}835}