authorgravatar for devnexen@gmail.comDavid Carlier <devnexen@gmail.com> 2023-05-25 20:32:17+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-05-25 14:32:17-05:00
log41502c6aa53a3da31b276c23c4db74db7d04796b
treeb1118c8e6c6042ff6fddeaf01dd97b2e236b52c2
parent230ea411f72303607a8c5c5467258eee61bd6939
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791)


12 files changed, 48 insertions(+), 1 deletions(-)

lib/std/Thread.zig+1-1
......@@ -690,7 +690,7 @@ const PosixThreadImpl = struct {
690690 defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
691691
692692 // Use the same set of parameters used by the libc-less impl.
693 const stack_size = std.math.max(config.stack_size, 16 * 1024);
693 const stack_size = std.math.max(config.stack_size, c.PTHREAD_STACK_MIN);
694694 assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
695695 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);
696696
lib/std/c/darwin.zig+6
......@@ -4155,3 +4155,9 @@ pub const vm_extmod_statistics_t = *vm_extmod_statistics;
41554155pub const vm_extmod_statistics_data_t = vm_extmod_statistics;
41564156
41574157pub extern "c" fn vm_stats(info: ?*anyopaque, count: *c_uint) kern_return_t;
4158
4159/// TODO refines if necessary
4160pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
4161 .arm, .aarch64 => 16 * 1024,
4162 else => 8 * 1024,
4163};
lib/std/c/dragonfly.zig+2
......@@ -1160,3 +1160,5 @@ pub const sigevent = extern struct {
11601160 sigev_value: sigval,
11611161 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
11621162};
1163
1164pub const PTHREAD_STACK_MIN = 16 * 1024;
lib/std/c/emscripten.zig+2
......@@ -9,3 +9,5 @@ pub const pthread_rwlock_t = extern struct {
99};
1010const __SIZEOF_PTHREAD_COND_T = 48;
1111const __SIZEOF_PTHREAD_MUTEX_T = 28;
12
13pub const PTHREAD_STACK_MIN = 2048;
lib/std/c/freebsd.zig+6
......@@ -2818,3 +2818,9 @@ pub const ptrace_cs_remote = extern struct {
28182818};
28192819
28202820pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: [*:0]u8, data: c_int) c_int;
2821
2822/// TODO refines if necessary
2823pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
2824 .x86, .powerpc => 4 * 512,
2825 else => 4 * 1024,
2826};
lib/std/c/haiku.zig+3
......@@ -1068,3 +1068,6 @@ pub const sigevent = extern struct {
10681068 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
10691069 sigev_notify_attributes: ?*pthread_attr_t,
10701070};
1071
1072/// TODO refines if necessary
1073pub const PTHREAD_STACK_MIN = 2 * 4096;
lib/std/c/linux.zig+12
......@@ -350,6 +350,18 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
350350};
351351const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
352352
353/// TODO refines if necessary
354pub const PTHREAD_STACK_MIN = switch (native_abi) {
355 .musl, .musleabi, .musleabihf => 2048,
356 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
357 .aarch64, .arm, .armeb, .powerpc, .powerpc64, .powerpc64le, .loongarch32, .loongarch64 => 131072,
358 .sparc64 => 24576,
359 else => 16 * 1024,
360 },
361 .android => if (@sizeOf(usize) == 8) 16 * 1024 else 8 * 1024,
362 else => 16 * 1024,
363};
364
353365pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
354366pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
355367
lib/std/c/minix.zig+2
......@@ -16,3 +16,5 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) {
1616 },
1717 else => unreachable,
1818};
19
20pub const PTHREAD_STACK_MIN = 16 * 1024;
lib/std/c/netbsd.zig+3
......@@ -1720,3 +1720,6 @@ pub const PIOD = struct {
17201720};
17211721
17221722pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: c_int) c_int;
1723
1724/// TODO refines if necessary
1725pub const PTHREAD_STACK_MIN = 16 * 1024;
lib/std/c/openbsd.zig+7
......@@ -1631,3 +1631,10 @@ pub const HW_ALLOWPOWERDOWN = 22;
16311631pub const HW_PERFPOLICY = 23;
16321632pub const HW_SMT = 24;
16331633pub const HW_NCPUONLINE = 25;
1634
1635/// TODO refines if necessary
1636pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
1637 .sparc64 => 1 << 13,
1638 .mips64 => 1 << 14,
1639 else => 1 << 12,
1640};
lib/std/c/solaris.zig+2
......@@ -1946,3 +1946,5 @@ pub const sigevent = extern struct {
19461946 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
19471947 sigev_notify_attributes: ?*pthread_attr_t,
19481948};
1949
1950pub const PTHREAD_STACK_MIN = if (@sizeOf(usize) == 8) 8 * 1024 else 4 * 1024;
lib/std/c/wasi.zig+2
......@@ -119,3 +119,5 @@ pub const POLL = struct {
119119 pub const HUP = 0x2000;
120120 pub const NVAL = 0x4000;
121121};
122
123pub const PTHREAD_STACK_MIN = 16 * 1024;