Browse Source

thread: set stack size to rlimit

Laytan Laats 1 month ago
parent
commit
25389ed086
1 changed files with 6 additions and 1 deletions
  1. 6 1
      core/thread/thread_unix.odin

+ 6 - 1
core/thread/thread_unix.odin

@@ -81,8 +81,13 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
 	}
 	defer posix.pthread_attr_destroy(&attrs)
 
-	// NOTE(tetra, 2019-11-01): These only fail if their argument is invalid.
+	stacksize: posix.rlimit
+	if res := posix.getrlimit(.STACK, &stacksize); res == .OK && stacksize.rlim_cur > 0 {
+		_ = posix.pthread_attr_setstacksize(&attrs, uint(stacksize.rlim_cur))
+	}
+
 	res: posix.Errno
+	// NOTE(tetra, 2019-11-01): These only fail if their argument is invalid.
 	res = posix.pthread_attr_setdetachstate(&attrs, .CREATE_JOINABLE)
 	assert(res == nil)
 	when ODIN_OS != .Haiku && ODIN_OS != .NetBSD {