| author | |
| committer | |
| log | 0a1def7833882249563358f262e2210beb77492a |
| tree | 5441edaf05de9ff0d0d2b33f130adbddffdb9fcd |
| parent | e16d3d162a85a822e16ae181ecc6ddc507278126 |
16 files changed, 130 insertions(+), 128 deletions(-)
lib/std/Thread/AutoResetEvent.zig+4-4| ... | ... | @@ -220,9 +220,9 @@ test "basic usage" { |
| 220 | 220 | }; |
| 221 | 221 | |
| 222 | 222 | var context = Context{}; |
| 223 | const send_thread = try std.Thread.spawn(Context.sender, &context); | |
| 224 | const recv_thread = try std.Thread.spawn(Context.receiver, &context); | |
| 223 | const send_thread = try std.Thread.spawn(.{}, Context.sender, .{&context}); | |
| 224 | const recv_thread = try std.Thread.spawn(.{}, Context.receiver, .{&context}); | |
| 225 | 225 | |
| 226 | send_thread.wait(); | |
| 227 | recv_thread.wait(); | |
| 226 | send_thread.join(); | |
| 227 | recv_thread.join(); | |
| 228 | 228 | } |
lib/std/Thread/Futex.zig+24-36| ... | ... | @@ -413,32 +413,27 @@ test "Futex - Signal" { |
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | const Thread = struct { | |
| 417 | tx: *Self, | |
| 418 | rx: *Self, | |
| 416 | const start_value = 1; | |
| 419 | 417 | |
| 420 | const start_value = 1; | |
| 421 | ||
| 422 | fn run(self: Thread) void { | |
| 423 | var iterations: u32 = start_value; | |
| 424 | while (iterations < 10) : (iterations += 1) { | |
| 425 | self.rx.recv(iterations); | |
| 426 | self.tx.send(iterations); | |
| 427 | } | |
| 418 | fn runThread(rx: *Self, tx: *Self) void { | |
| 419 | var iterations: u32 = start_value; | |
| 420 | while (iterations < 10) : (iterations += 1) { | |
| 421 | self.rx.recv(iterations); | |
| 422 | self.tx.send(iterations); | |
| 428 | 423 | } |
| 429 | }; | |
| 424 | } | |
| 430 | 425 | |
| 431 | 426 | fn run() !void { |
| 432 | 427 | var ping = Self{}; |
| 433 | 428 | var pong = Self{}; |
| 434 | 429 | |
| 435 | const t1 = try std.Thread.spawn(Thread.run, .{ .rx = &ping, .tx = &pong }); | |
| 436 | defer t1.wait(); | |
| 430 | const t1 = try std.Thread.spawn(.{}, runThread, .{ &ping, &pong }); | |
| 431 | defer t1.join(); | |
| 437 | 432 | |
| 438 | const t2 = try std.Thread.spawn(Thread.run, .{ .rx = &pong, .tx = &ping }); | |
| 439 | defer t2.wait(); | |
| 433 | const t2 = try std.Thread.spawn(.{}, runThread, .{ &pong, &ping }); | |
| 434 | defer t2.join(); | |
| 440 | 435 | |
| 441 | ping.send(Thread.start_value); | |
| 436 | ping.send(start_value); | |
| 442 | 437 | } |
| 443 | 438 | }).run(); |
| 444 | 439 | } |
| ... | ... | @@ -507,7 +502,7 @@ test "Futex - Chain" { |
| 507 | 502 | try (struct { |
| 508 | 503 | completed: Signal = .{}, |
| 509 | 504 | threads: [10]struct { |
| 510 | thread: *std.Thread, | |
| 505 | thread: std.Thread, | |
| 511 | 506 | signal: Signal, |
| 512 | 507 | } = undefined, |
| 513 | 508 | |
| ... | ... | @@ -531,39 +526,32 @@ test "Futex - Chain" { |
| 531 | 526 | }; |
| 532 | 527 | |
| 533 | 528 | const Self = @This(); |
| 534 | const Chain = struct { | |
| 535 | self: *Self, | |
| 536 | index: usize, | |
| 537 | 529 | |
| 538 | fn run(chain: Chain) void { | |
| 539 | const this_signal = &chain.self.threads[chain.index].signal; | |
| 530 | fn runThread(self: *Self, index: usize) void { | |
| 531 | const this_signal = &chain.self.threads[chain.index].signal; | |
| 540 | 532 | |
| 541 | var next_signal = &chain.self.completed; | |
| 542 | if (chain.index + 1 < chain.self.threads.len) { | |
| 543 | next_signal = &chain.self.threads[chain.index + 1].signal; | |
| 544 | } | |
| 545 | ||
| 546 | this_signal.wait(); | |
| 547 | next_signal.notify(); | |
| 533 | var next_signal = &chain.self.completed; | |
| 534 | if (chain.index + 1 < chain.self.threads.len) { | |
| 535 | next_signal = &chain.self.threads[chain.index + 1].signal; | |
| 548 | 536 | } |
| 549 | }; | |
| 537 | ||
| 538 | this_signal.wait(); | |
| 539 | next_signal.notify(); | |
| 540 | } | |
| 550 | 541 | |
| 551 | 542 | fn run() !void { |
| 552 | 543 | var self = Self{}; |
| 553 | 544 | |
| 554 | 545 | for (self.threads) |*entry, index| { |
| 555 | 546 | entry.signal = .{}; |
| 556 | entry.thread = try std.Thread.spawn(Chain.run, .{ | |
| 557 | .self = &self, | |
| 558 | .index = index, | |
| 559 | }); | |
| 547 | entry.thread = try std.Thread.spawn(.{}, runThread .{&self, index}); | |
| 560 | 548 | } |
| 561 | 549 | |
| 562 | 550 | self.threads[0].signal.notify(); |
| 563 | 551 | self.completed.wait(); |
| 564 | 552 | |
| 565 | 553 | for (self.threads) |entry| { |
| 566 | entry.thread.wait(); | |
| 554 | entry.thread.join(); | |
| 567 | 555 | } |
| 568 | 556 | } |
| 569 | 557 | }).run(); |
lib/std/Thread/Mutex.zig+3-3| ... | ... | @@ -297,12 +297,12 @@ test "basic usage" { |
| 297 | 297 | try testing.expect(context.data == TestContext.incr_count); |
| 298 | 298 | } else { |
| 299 | 299 | const thread_count = 10; |
| 300 | var threads: [thread_count]*std.Thread = undefined; | |
| 300 | var threads: [thread_count]std.Thread = undefined; | |
| 301 | 301 | for (threads) |*t| { |
| 302 | t.* = try std.Thread.spawn(worker, &context); | |
| 302 | t.* = try std.Thread.spawn(.{}, worker, .{&context}); | |
| 303 | 303 | } |
| 304 | 304 | for (threads) |t| |
| 305 | t.wait(); | |
| 305 | t.join(); | |
| 306 | 306 | |
| 307 | 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 | 281 | var context: Context = undefined; |
| 282 | 282 | try context.init(); |
| 283 | 283 | defer context.deinit(); |
| 284 | const receiver = try std.Thread.spawn(Context.receiver, &context); | |
| 285 | defer receiver.wait(); | |
| 284 | const receiver = try std.Thread.spawn(.{}, Context.receiver, .{&context}); | |
| 285 | defer receiver.join(); | |
| 286 | 286 | try context.sender(); |
| 287 | 287 | |
| 288 | 288 | if (false) { |
| ... | ... | @@ -290,8 +290,8 @@ test "basic usage" { |
| 290 | 290 | // https://github.com/ziglang/zig/issues/7009 |
| 291 | 291 | var timed = Context.init(); |
| 292 | 292 | defer timed.deinit(); |
| 293 | const sleeper = try std.Thread.spawn(Context.sleeper, &timed); | |
| 294 | defer sleeper.wait(); | |
| 293 | const sleeper = try std.Thread.spawn(.{}, Context.sleeper, .{&timed}); | |
| 294 | defer sleeper.join(); | |
| 295 | 295 | try timed.timedWaiter(); |
| 296 | 296 | } |
| 297 | 297 | } |
lib/std/Thread/StaticResetEvent.zig+4-4| ... | ... | @@ -384,8 +384,8 @@ test "basic usage" { |
| 384 | 384 | }; |
| 385 | 385 | |
| 386 | 386 | var context = Context{}; |
| 387 | const receiver = try std.Thread.spawn(Context.receiver, &context); | |
| 388 | defer receiver.wait(); | |
| 387 | const receiver = try std.Thread.spawn(.{}, Context.receiver, .{&context}); | |
| 388 | defer receiver.join(); | |
| 389 | 389 | try context.sender(); |
| 390 | 390 | |
| 391 | 391 | if (false) { |
| ... | ... | @@ -393,8 +393,8 @@ test "basic usage" { |
| 393 | 393 | // https://github.com/ziglang/zig/issues/7009 |
| 394 | 394 | var timed = Context.init(); |
| 395 | 395 | defer timed.deinit(); |
| 396 | const sleeper = try std.Thread.spawn(Context.sleeper, &timed); | |
| 397 | defer sleeper.wait(); | |
| 396 | const sleeper = try std.Thread.spawn(.{}, Context.sleeper, .{&timed}); | |
| 397 | defer sleeper.join(); | |
| 398 | 398 | try timed.timedWaiter(); |
| 399 | 399 | } |
| 400 | 400 | } |
lib/std/atomic/queue.zig+6-6| ... | ... | @@ -214,20 +214,20 @@ test "std.atomic.Queue" { |
| 214 | 214 | } else { |
| 215 | 215 | try expect(context.queue.isEmpty()); |
| 216 | 216 | |
| 217 | var putters: [put_thread_count]*std.Thread = undefined; | |
| 217 | var putters: [put_thread_count]std.Thread = undefined; | |
| 218 | 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 | 222 | for (getters) |*t| { |
| 223 | t.* = try std.Thread.spawn(startGets, &context); | |
| 223 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | for (putters) |t| |
| 227 | t.wait(); | |
| 227 | t.join(); | |
| 228 | 228 | @atomicStore(bool, &context.puts_done, true, .SeqCst); |
| 229 | 229 | for (getters) |t| |
| 230 | t.wait(); | |
| 230 | t.join(); | |
| 231 | 231 | |
| 232 | 232 | try expect(context.queue.isEmpty()); |
| 233 | 233 | } |
lib/std/atomic/stack.zig+6-6| ... | ... | @@ -121,20 +121,20 @@ test "std.atomic.stack" { |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | var putters: [put_thread_count]*std.Thread = undefined; | |
| 124 | var putters: [put_thread_count]std.Thread = undefined; | |
| 125 | 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 | 129 | for (getters) |*t| { |
| 130 | t.* = try std.Thread.spawn(startGets, &context); | |
| 130 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | for (putters) |t| |
| 134 | t.wait(); | |
| 134 | t.join(); | |
| 135 | 135 | @atomicStore(bool, &context.puts_done, true, .SeqCst); |
| 136 | 136 | for (getters) |t| |
| 137 | t.wait(); | |
| 137 | t.join(); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 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 | 273 | if (builtin.single_threaded) { |
| 274 | 274 | stderr.print("panic: ", .{}) catch os.abort(); |
| 275 | 275 | } else { |
| 276 | const current_thread_id = std.Thread.getCurrentThreadId(); | |
| 277 | stderr.print("thread {d} panic: ", .{current_thread_id}) catch os.abort(); | |
| 276 | const current_thread_id = std.Thread.getCurrentId(); | |
| 277 | stderr.print("thread {} panic: ", .{current_thread_id}) catch os.abort(); | |
| 278 | 278 | } |
| 279 | 279 | stderr.print(format ++ "\n", args) catch os.abort(); |
| 280 | 280 | if (trace) |t| { |
lib/std/event/loop.zig+15-15| ... | ... | @@ -21,12 +21,12 @@ pub const Loop = struct { |
| 21 | 21 | os_data: OsData, |
| 22 | 22 | final_resume_node: ResumeNode, |
| 23 | 23 | pending_event_count: usize, |
| 24 | extra_threads: []*Thread, | |
| 24 | extra_threads: []Thread, | |
| 25 | 25 | /// TODO change this to a pool of configurable number of threads |
| 26 | 26 | /// and rename it to be not file-system-specific. it will become |
| 27 | 27 | /// a thread pool for turning non-CPU-bound blocking things into |
| 28 | 28 | /// async things. A fallback for any missing OS-specific API. |
| 29 | fs_thread: *Thread, | |
| 29 | fs_thread: Thread, | |
| 30 | 30 | fs_queue: std.atomic.Queue(Request), |
| 31 | 31 | fs_end_request: Request.Node, |
| 32 | 32 | fs_thread_wakeup: std.Thread.ResetEvent, |
| ... | ... | @@ -189,11 +189,11 @@ pub const Loop = struct { |
| 189 | 189 | errdefer self.deinitOsData(); |
| 190 | 190 | |
| 191 | 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 | 194 | errdefer if (!builtin.single_threaded) { |
| 195 | 195 | self.posixFsRequest(&self.fs_end_request); |
| 196 | self.fs_thread.wait(); | |
| 196 | self.fs_thread.join(); | |
| 197 | 197 | }; |
| 198 | 198 | |
| 199 | 199 | if (!std.builtin.single_threaded) |
| ... | ... | @@ -264,11 +264,11 @@ pub const Loop = struct { |
| 264 | 264 | assert(amt == wakeup_bytes.len); |
| 265 | 265 | while (extra_thread_index != 0) { |
| 266 | 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 | 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 | 274 | .macos, .freebsd, .netbsd, .dragonfly, .openbsd => { |
| ... | ... | @@ -329,11 +329,11 @@ pub const Loop = struct { |
| 329 | 329 | _ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable; |
| 330 | 330 | while (extra_thread_index != 0) { |
| 331 | 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 | 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 | 339 | .windows => { |
| ... | ... | @@ -378,11 +378,11 @@ pub const Loop = struct { |
| 378 | 378 | } |
| 379 | 379 | while (extra_thread_index != 0) { |
| 380 | 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 | 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 | 388 | else => {}, |
| ... | ... | @@ -651,18 +651,18 @@ pub const Loop = struct { |
| 651 | 651 | .netbsd, |
| 652 | 652 | .dragonfly, |
| 653 | 653 | .openbsd, |
| 654 | => self.fs_thread.wait(), | |
| 654 | => self.fs_thread.join(), | |
| 655 | 655 | else => {}, |
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | for (self.extra_threads) |extra_thread| { |
| 660 | extra_thread.wait(); | |
| 660 | extra_thread.join(); | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | @atomicStore(bool, &self.delay_queue.is_running, false, .SeqCst); |
| 664 | 664 | self.delay_queue.event.set(); |
| 665 | self.delay_queue.thread.wait(); | |
| 665 | self.delay_queue.thread.join(); | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /// Runs the provided function asynchronously. The function's frame is allocated |
| ... | ... | @@ -787,7 +787,7 @@ pub const Loop = struct { |
| 787 | 787 | const DelayQueue = struct { |
| 788 | 788 | timer: std.time.Timer, |
| 789 | 789 | waiters: Waiters, |
| 790 | thread: *std.Thread, | |
| 790 | thread: std.Thread, | |
| 791 | 791 | event: std.Thread.AutoResetEvent, |
| 792 | 792 | is_running: bool, |
| 793 | 793 | |
| ... | ... | @@ -802,7 +802,7 @@ pub const Loop = struct { |
| 802 | 802 | .event = std.Thread.AutoResetEvent{}, |
| 803 | 803 | .is_running = true, |
| 804 | 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 | } |
| 808 | 808 |
lib/std/fs/test.zig+5-6| ... | ... | @@ -862,11 +862,10 @@ test "open file with exclusive lock twice, make sure it waits" { |
| 862 | 862 | errdefer file.close(); |
| 863 | 863 | |
| 864 | 864 | const S = struct { |
| 865 | const C = struct { dir: *fs.Dir, evt: *std.Thread.ResetEvent }; | |
| 866 | fn checkFn(ctx: C) !void { | |
| 867 | const file1 = try ctx.dir.createFile(filename, .{ .lock = .Exclusive }); | |
| 865 | fn checkFn(dir: *fs.Dir, evt: *std.Thread.ResetEvent) !void { | |
| 866 | const file1 = try dir.createFile(filename, .{ .lock = .Exclusive }); | |
| 868 | 867 | defer file1.close(); |
| 869 | ctx.evt.set(); | |
| 868 | evt.set(); | |
| 870 | 869 | } |
| 871 | 870 | }; |
| 872 | 871 | |
| ... | ... | @@ -874,8 +873,8 @@ test "open file with exclusive lock twice, make sure it waits" { |
| 874 | 873 | try evt.init(); |
| 875 | 874 | defer evt.deinit(); |
| 876 | 875 | |
| 877 | const t = try std.Thread.spawn(S.checkFn, S.C{ .dir = &tmp.dir, .evt = &evt }); | |
| 878 | defer t.wait(); | |
| 876 | const t = try std.Thread.spawn(.{}, S.checkFn, .{ &tmp.dir, &evt }); | |
| 877 | defer t.join(); | |
| 879 | 878 | |
| 880 | 879 | const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms; |
| 881 | 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 | 161 | } |
| 162 | 162 | }; |
| 163 | 163 | |
| 164 | const t = try std.Thread.spawn(S.clientFn, server.listen_address); | |
| 165 | defer t.wait(); | |
| 164 | const t = try std.Thread.spawn(.{}, S.clientFn, .{server.listen_address}); | |
| 165 | defer t.join(); | |
| 166 | 166 | |
| 167 | 167 | var client = try server.accept(); |
| 168 | 168 | defer client.stream.close(); |
| ... | ... | @@ -277,7 +277,7 @@ test "listen on a unix socket, send bytes, receive bytes" { |
| 277 | 277 | try server.listen(socket_addr); |
| 278 | 278 | |
| 279 | 279 | const S = struct { |
| 280 | fn clientFn(_: void) !void { | |
| 280 | fn clientFn() !void { | |
| 281 | 281 | const socket = try net.connectUnixSocket(socket_path); |
| 282 | 282 | defer socket.close(); |
| 283 | 283 | |
| ... | ... | @@ -285,8 +285,8 @@ test "listen on a unix socket, send bytes, receive bytes" { |
| 285 | 285 | } |
| 286 | 286 | }; |
| 287 | 287 | |
| 288 | const t = try std.Thread.spawn(S.clientFn, {}); | |
| 289 | defer t.wait(); | |
| 288 | const t = try std.Thread.spawn(.{}, S.clientFn, .{}); | |
| 289 | defer t.join(); | |
| 290 | 290 | |
| 291 | 291 | var client = try server.accept(); |
| 292 | 292 | defer client.stream.close(); |
lib/std/once.zig+4-4| ... | ... | @@ -55,16 +55,16 @@ test "Once executes its function just once" { |
| 55 | 55 | global_once.call(); |
| 56 | 56 | global_once.call(); |
| 57 | 57 | } else { |
| 58 | var threads: [10]*std.Thread = undefined; | |
| 59 | defer for (threads) |handle| handle.wait(); | |
| 58 | var threads: [10]std.Thread = undefined; | |
| 59 | defer for (threads) |handle| handle.join(); | |
| 60 | 60 | |
| 61 | 61 | for (threads) |*handle| { |
| 62 | handle.* = try std.Thread.spawn(struct { | |
| 62 | handle.* = try std.Thread.spawn(.{}, struct { | |
| 63 | 63 | fn thread_fn(x: u8) void { |
| 64 | 64 | _ = x; |
| 65 | 65 | global_once.call(); |
| 66 | 66 | } |
| 67 | }.thread_fn, 0); | |
| 67 | }.thread_fn, .{0}); | |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 |
lib/std/os/test.zig+17-19| ... | ... | @@ -320,9 +320,9 @@ test "std.Thread.getCurrentId" { |
| 320 | 320 | if (builtin.single_threaded) return error.SkipZigTest; |
| 321 | 321 | |
| 322 | 322 | var thread_current_id: Thread.Id = undefined; |
| 323 | const thread = try Thread.spawn(testThreadIdFn, &thread_current_id); | |
| 324 | const thread_id = thread.handle(); | |
| 325 | thread.wait(); | |
| 323 | const thread = try Thread.spawn(.{}, testThreadIdFn, .{&thread_current_id}); | |
| 324 | const thread_id = thread.getHandle(); | |
| 325 | thread.join(); | |
| 326 | 326 | if (Thread.use_pthreads) { |
| 327 | 327 | try expect(thread_current_id == thread_id); |
| 328 | 328 | } else if (native_os == .windows) { |
| ... | ... | @@ -339,21 +339,20 @@ test "spawn threads" { |
| 339 | 339 | |
| 340 | 340 | var shared_ctx: i32 = 1; |
| 341 | 341 | |
| 342 | const thread1 = try Thread.spawn(start1, {}); | |
| 343 | const thread2 = try Thread.spawn(start2, &shared_ctx); | |
| 344 | const thread3 = try Thread.spawn(start2, &shared_ctx); | |
| 345 | const thread4 = try Thread.spawn(start2, &shared_ctx); | |
| 342 | const thread1 = try Thread.spawn(.{}, start1, .{}); | |
| 343 | const thread2 = try Thread.spawn(.{}, start2, .{&shared_ctx}); | |
| 344 | const thread3 = try Thread.spawn(.{}, start2, .{&shared_ctx}); | |
| 345 | const thread4 = try Thread.spawn(.{}, start2, .{&shared_ctx}); | |
| 346 | 346 | |
| 347 | thread1.wait(); | |
| 348 | thread2.wait(); | |
| 349 | thread3.wait(); | |
| 350 | thread4.wait(); | |
| 347 | thread1.join(); | |
| 348 | thread2.join(); | |
| 349 | thread3.join(); | |
| 350 | thread4.join(); | |
| 351 | 351 | |
| 352 | 352 | try expect(shared_ctx == 4); |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | fn start1(ctx: void) u8 { | |
| 356 | _ = ctx; | |
| 355 | fn start1() u8 { | |
| 357 | 356 | return 0; |
| 358 | 357 | } |
| 359 | 358 | |
| ... | ... | @@ -371,16 +370,15 @@ test "cpu count" { |
| 371 | 370 | |
| 372 | 371 | test "thread local storage" { |
| 373 | 372 | if (builtin.single_threaded) return error.SkipZigTest; |
| 374 | const thread1 = try Thread.spawn(testTls, {}); | |
| 375 | const thread2 = try Thread.spawn(testTls, {}); | |
| 373 | const thread1 = try Thread.spawn(.{}, testTls, .{}); | |
| 374 | const thread2 = try Thread.spawn(.{}, testTls, .{}); | |
| 376 | 375 | try testTls({}); |
| 377 | thread1.wait(); | |
| 378 | thread2.wait(); | |
| 376 | thread1.join(); | |
| 377 | thread2.join(); | |
| 379 | 378 | } |
| 380 | 379 | |
| 381 | 380 | threadlocal var x: i32 = 1234; |
| 382 | fn testTls(context: void) !void { | |
| 383 | _ = context; | |
| 381 | fn testTls() !void { | |
| 384 | 382 | if (x != 1234) return error.TlsBadStartValue; |
| 385 | 383 | x += 1; |
| 386 | 384 | if (x != 1235) return error.TlsBadEndValue; |
lib/std/target.zig+19-4| ... | ... | @@ -69,6 +69,13 @@ pub const Target = struct { |
| 69 | 69 | }; |
| 70 | 70 | } |
| 71 | 71 | |
| 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 | 79 | pub fn dynamicLibSuffix(tag: Tag) [:0]const u8 { |
| 73 | 80 | if (tag.isDarwin()) { |
| 74 | 81 | return ".dylib"; |
| ... | ... | @@ -787,6 +794,13 @@ pub const Target = struct { |
| 787 | 794 | }; |
| 788 | 795 | } |
| 789 | 796 | |
| 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 | 804 | pub fn isThumb(arch: Arch) bool { |
| 791 | 805 | return switch (arch) { |
| 792 | 806 | .thumb, .thumbeb => true, |
| ... | ... | @@ -1365,10 +1379,7 @@ pub const Target = struct { |
| 1365 | 1379 | } |
| 1366 | 1380 | |
| 1367 | 1381 | pub fn isAndroid(self: Target) bool { |
| 1368 | return switch (self.abi) { | |
| 1369 | .android => true, | |
| 1370 | else => false, | |
| 1371 | }; | |
| 1382 | return self.abi == .android; | |
| 1372 | 1383 | } |
| 1373 | 1384 | |
| 1374 | 1385 | pub fn isWasm(self: Target) bool { |
| ... | ... | @@ -1379,6 +1390,10 @@ pub const Target = struct { |
| 1379 | 1390 | return self.os.tag.isDarwin(); |
| 1380 | 1391 | } |
| 1381 | 1392 | |
| 1393 | pub fn isBSD(self: Target) bool { | |
| 1394 | return self.os.tag.isBSD(); | |
| 1395 | } | |
| 1396 | ||
| 1382 | 1397 | pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool { |
| 1383 | 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 | 74 | try worker.idle_node.data.init(); |
| 75 | 75 | errdefer worker.idle_node.data.deinit(); |
| 76 | 76 | |
| 77 | worker.thread = try std.Thread.spawn(Worker.run, worker); | |
| 77 | worker.thread = try std.Thread.spawn(.{}, Worker.run, .{worker}); | |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | fn destroyWorkers(self: *ThreadPool, spawned: usize) void { |
| 82 | 82 | for (self.workers[0..spawned]) |*worker| { |
| 83 | worker.thread.wait(); | |
| 83 | worker.thread.join(); | |
| 84 | 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 | 816 | }); |
| 817 | 817 | } |
| 818 | 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 | 820 | for (llvm_targets) |llvm_target, i| { |
| 821 | threads[i] = try std.Thread.spawn(processOneTarget, .{ | |
| 822 | .llvm_tblgen_exe = llvm_tblgen_exe, | |
| 823 | .llvm_src_root = llvm_src_root, | |
| 824 | .zig_src_dir = zig_src_dir, | |
| 825 | .root_progress = root_progress, | |
| 826 | .llvm_target = llvm_target, | |
| 821 | threads[i] = try std.Thread.spawn(.{}, processOneTarget, .{ | |
| 822 | Job{ | |
| 823 | .llvm_tblgen_exe = llvm_tblgen_exe, | |
| 824 | .llvm_src_root = llvm_src_root, | |
| 825 | .zig_src_dir = zig_src_dir, | |
| 826 | .root_progress = root_progress, | |
| 827 | .llvm_target = llvm_target, | |
| 828 | }, | |
| 827 | 829 | }); |
| 828 | 830 | } |
| 829 | 831 | for (threads) |thread| { |
| 830 | thread.wait(); | |
| 832 | thread.join(); | |
| 831 | 833 | } |
| 832 | 834 | } |
| 833 | 835 | } |