authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-20 09:56:30-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:49:00-05:00
logca1e61b851351ec66ee3f1937586a2f9d02bbafc
treeafc244dca5bbb1089e52ef55d22bb7eacfbd0dde
parent6ff64895cf0c8f331959d34dec5f4fa84e7c6365

std.Thread: fix some typos


2 files changed, 15 insertions(+), 21 deletions(-)

lib/std/Thread.zig+14-20
...@@ -24,16 +24,14 @@ pub const Condition = @import("Thread/Condition.zig");...@@ -24,16 +24,14 @@ pub const Condition = @import("Thread/Condition.zig");
24pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");24pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
2525
26test "std.Thread" {26test "std.Thread" {
27 if (!builtin.single_threaded) {27 // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.
28 // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.28 _ = AutoResetEvent;
29 _ = AutoResetEvent;29 _ = Futex;
30 _ = Futex;30 _ = ResetEvent;
31 _ = ResetEvent;31 _ = StaticResetEvent;
32 _ = StaticResetEvent;32 _ = Mutex;
33 _ = Mutex;33 _ = Semaphore;
34 _ = Semaphore;34 _ = Condition;
35 _ = Condition;
36 }
37}35}
3836
39pub const use_pthreads = target.os.tag != .windows and std.builtin.link_libc;37pub const use_pthreads = target.os.tag != .windows and std.builtin.link_libc;
...@@ -114,17 +112,13 @@ pub const SpawnError = error {...@@ -114,17 +112,13 @@ pub const SpawnError = error {
114/// `config` can be used as hints to the platform for now to spawn and execute the `function`.112/// `config` can be used as hints to the platform for now to spawn and execute the `function`.
115/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources113/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources
116/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.114/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.
117pub fn spawn(115pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
118 config: SpawnConfig,
119 comptime function: anytype,
120 args: std.meta.ArgsTuple(function),
121) SpawnError!Thread {
122 if (std.builtin.single_threaded) {116 if (std.builtin.single_threaded) {
123 @compileError("cannot spawn thread when building in single-threaded mode");117 @compileError("cannot spawn thread when building in single-threaded mode");
124 }118 }
125119
126 const impl = try Thread.spawn(config, function, args);120 const impl = try Impl.spawn(config, function, args);
127 return .{ .impl = impl };121 return Thread{ .impl = impl };
128}122}
129123
130/// Represents a kernel thread handle.124/// Represents a kernel thread handle.
...@@ -438,7 +432,7 @@ const LinuxThreadImpl = struct {...@@ -438,7 +432,7 @@ const LinuxThreadImpl = struct {
438432
439 fn getCurrentId() Id {433 fn getCurrentId() Id {
440 return tls_thread_id orelse {434 return tls_thread_id orelse {
441 const tid = linux.gettid();435 const tid = @bitCast(u32, linux.gettid());
442 tls_thread_id = tid;436 tls_thread_id = tid;
443 return tid;437 return tid;
444 };438 };
...@@ -550,7 +544,7 @@ const LinuxThreadImpl = struct {...@@ -550,7 +544,7 @@ const LinuxThreadImpl = struct {
550 const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset]));544 const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset]));
551 instance.* = .{545 instance.* = .{
552 .fn_args = args,546 .fn_args = args,
553 .thread = .{ .mapped = .mapped },547 .thread = .{ .mapped = mapped },
554 };548 };
555549
556 const flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES |550 const flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES |
...@@ -591,7 +585,7 @@ const LinuxThreadImpl = struct {...@@ -591,7 +585,7 @@ const LinuxThreadImpl = struct {
591 }585 }
592586
593 fn join(self: Impl) void {587 fn join(self: Impl) void {
594 defer self.thread.free();588 defer os.munmap(self.thread.mapped);
595589
596 var spin: u8 = 10;590 var spin: u8 = 10;
597 while (true) {591 while (true) {
lib/std/Thread/Futex.zig+1-1
...@@ -544,7 +544,7 @@ test "Futex - Chain" {...@@ -544,7 +544,7 @@ test "Futex - Chain" {
544544
545 for (self.threads) |*entry, index| {545 for (self.threads) |*entry, index| {
546 entry.signal = .{};546 entry.signal = .{};
547 entry.thread = try std.Thread.spawn(.{}, runThread .{&self, index});547 entry.thread = try std.Thread.spawn(.{}, runThread, .{&self, index});
548 }548 }
549549
550 self.threads[0].signal.notify();550 self.threads[0].signal.notify();