diff options
| author | kprotty <kbutcher6200@gmail.com> | 2021-06-26 10:52:34 -0500 |
|---|---|---|
| committer | kprotty <kbutcher6200@gmail.com> | 2021-06-30 21:49:00 -0500 |
| commit | c6fb968a3d702fbf8067164052ccf562f5e362ef (patch) | |
| tree | 999e66ef1066e813c788df367e0ced2243b1ed94 /lib/std/Thread.zig | |
| parent | fd4a607bb2f1a1cbf8b8c1fd5d35f5f775e79114 (diff) | |
| download | zig-c6fb968a3d702fbf8067164052ccf562f5e362ef.tar.gz zig-c6fb968a3d702fbf8067164052ccf562f5e362ef.zip | |
std.Thread: fix posix
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 19987d47a1..db049b5d21 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -376,11 +376,16 @@ const PosixThreadImpl = struct { fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl { const Args = @TypeOf(args); const allocator = std.heap.c_allocator; + const Instance = struct { fn entryFn(raw_arg: ?*c_void) callconv(.C) ?*c_void { - const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg orelse unreachable)); - defer allocator.destroy(args_ptr); - return callFn(f, args_ptr.*); + if (@sizeOf(Args) < 1) { + return callFn(f, @as(Args, undefined)); + } + + const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg)); + defer allocator.destroy(args_ptr); + return callFn(f, args_ptr.*); } }; @@ -402,7 +407,7 @@ const PosixThreadImpl = struct { &handle, &attr, Instance.entryFn, - @ptrCast(*c_void, args_ptr), + if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined, )) { 0 => return Impl{ .handle = handle }, os.EAGAIN => return error.SystemResources, |
