Skip to content

Commit

Permalink
bpo-18049: Sync thread stack size to main thread size on macOS (GH-14748
Browse files Browse the repository at this point in the history
)

This changeset increases the default size of the stack
for threads on macOS to the size of the stack
of the main thread and reenables the relevant
recursion test.
(cherry picked from commit 1a057ba)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
  • Loading branch information
miss-islington and ronaldoussoren committed Aug 1, 2019
1 parent dcc53eb commit 8399641
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Lib/test/test_threading.py
Expand Up @@ -1049,8 +1049,6 @@ def test_releasing_unacquired_lock(self):
lock = threading.Lock()
self.assertRaises(RuntimeError, lock.release)

@unittest.skipUnless(sys.platform == 'darwin' and test.support.python_is_optimized(),
'test macosx problem')
def test_recursion_limit(self):
# Issue 9670
# test that excessive recursion within a non-main thread causes
Expand Down
@@ -0,0 +1,3 @@
Increase the default stack size of threads from 5MB to 16MB on macOS, to
match the stack size of the main thread. This avoids crashes on deep recursion
in threads.
3 changes: 2 additions & 1 deletion Python/thread_pthread.h
Expand Up @@ -40,7 +40,8 @@
*/
#if defined(__APPLE__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0
#undef THREAD_STACK_SIZE
#define THREAD_STACK_SIZE 0x500000
/* Note: This matches the value of -Wl,-stack_size in configure.ac */
#define THREAD_STACK_SIZE 0x1000000
#endif
#if defined(__FreeBSD__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0
#undef THREAD_STACK_SIZE
Expand Down
2 changes: 2 additions & 0 deletions configure
Expand Up @@ -9542,6 +9542,8 @@ then
# Issue #18075: the default maximum stack size (8MBytes) is too
# small for the default recursion limit. Increase the stack size
# to ensure that tests don't crash
# Note: This matches the value of THREAD_STACK_SIZE in
# thread_pthread.h
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"

if test "$enable_framework"
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Expand Up @@ -2694,6 +2694,8 @@ then
# Issue #18075: the default maximum stack size (8MBytes) is too
# small for the default recursion limit. Increase the stack size
# to ensure that tests don't crash
# Note: This matches the value of THREAD_STACK_SIZE in
# thread_pthread.h
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"

if test "$enable_framework"
Expand Down

0 comments on commit 8399641

Please sign in to comment.