Merge pull request #112094 from mihe/apple-stack-size
Increase stack size for all secondary threads on Apple platforms
This commit is contained in:
@ -92,9 +92,20 @@ Thread::ID Thread::start(Thread::Callback p_callback, void *p_user, const Settin
|
||||
break;
|
||||
}
|
||||
|
||||
if (p_settings.stack_size > 0) {
|
||||
pthread_attr_setstacksize(&attr, p_settings.stack_size);
|
||||
}
|
||||
// The default stack size for secondary threads on Apple platforms is 512KiB.
|
||||
// This is insufficient when using a library like SPIRV-Cross, which can generate deep stacks and result in a stack overflow.
|
||||
// It also creates a problematic discrepancy with other platforms, where secondary threads are often at least 1 MiB.
|
||||
pthread_attr_setstacksize(&attr,
|
||||
#if __has_feature(address_sanitizer) || __has_feature(thread_sanitizer)
|
||||
// ASan (and to some degree TSan) needs a lot of extra stack size.
|
||||
4 * 1024 * 1024 // 4 MiB
|
||||
#elif !defined(__OPTIMIZE__)
|
||||
// Unoptimized builds also need a larger stack size.
|
||||
2 * 1024 * 1024 // 2 MiB
|
||||
#else
|
||||
1 * 1024 * 1024 // 1 MiB
|
||||
#endif
|
||||
);
|
||||
|
||||
// Create the thread
|
||||
pthread_create(&pthread, &attr, thread_callback, thread_data);
|
||||
|
||||
@ -57,8 +57,6 @@ public:
|
||||
|
||||
struct Settings {
|
||||
Priority priority;
|
||||
/// Override the default stack size (0 means default)
|
||||
uint64_t stack_size = 0;
|
||||
Settings() { priority = PRIORITY_NORMAL; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user