Skip to content

Commit 48cb14a

Browse files
committed
queue: use the default stack size on Windows
The Windows thread pool implementation is calling `_beginthreadex` with a stack size of 64 KB. This seems like a misunderstanding to me. In the pthread code, `_dispatch_mgr_root_queue_init` does call `pthread_attr_setstacksize` with a 64 KB size. However, this only applies to the pthread root queue manager, and pthread root queues are only supported on Apple platforms anyway. We can confirm that using the OS default stack size is the intended semantic by looking at the `dispatch_select` test, which expects to be able to stack-allocate a 500 KB buffer in an event handler. This test is failing on Windows because there is not enough stack space. We've also run into various related issues in Swift which only happen on Windows, and I suspect that this is just because the stack size isn't so small on other platforms.
1 parent f6e30ed commit 48cb14a

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/queue.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5769,13 +5769,8 @@ _dispatch_root_queue_poke_slow(dispatch_queue_global_t dq, int n, int floor)
57695769
#endif
57705770
do {
57715771
_dispatch_retain(dq); // released in _dispatch_worker_thread
5772-
#if DISPATCH_DEBUG
5773-
unsigned dwStackSize = 0;
5774-
#else
5775-
unsigned dwStackSize = 64 * 1024;
5776-
#endif
57775772
uintptr_t hThread = 0;
5778-
while (!(hThread = _beginthreadex(NULL, dwStackSize, _dispatch_worker_thread_thunk, dq, STACK_SIZE_PARAM_IS_A_RESERVATION, NULL))) {
5773+
while (!(hThread = _beginthreadex(NULL, /* stack_size */ 0, _dispatch_worker_thread_thunk, dq, STACK_SIZE_PARAM_IS_A_RESERVATION, NULL))) {
57795774
if (errno != EAGAIN) {
57805775
(void)dispatch_assume(hThread);
57815776
}

0 commit comments

Comments
 (0)