From 3e27444bea771e25102430bfa632edf8d106c91c Mon Sep 17 00:00:00 2001
From: Jerry James <loganjerry@gmail.com>
Date: Mon, 9 Aug 2021 15:37:39 -0600
Subject: [PATCH] Adapt to nonconstant PTHREAD_STACK_MIN in glibc 2.34+

---
 libpolyml/sighandler.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libpolyml/sighandler.cpp b/libpolyml/sighandler.cpp
index fd6f6e3e..5d22b000 100644
--- a/libpolyml/sighandler.cpp
+++ b/libpolyml/sighandler.cpp
@@ -547,11 +547,11 @@ void SigHandler::Init(void)
     pthread_attr_t attrs;
     pthread_attr_init(&attrs);
 #ifdef PTHREAD_STACK_MIN
-#if (PTHREAD_STACK_MIN < 4096)
-    pthread_attr_setstacksize(&attrs, 4096); // But not too small: FreeBSD makes it 2k
-#else
-    pthread_attr_setstacksize(&attrs, PTHREAD_STACK_MIN); // Only small stack.
-#endif
+    // In glibc 2.34 and later, PTHREAD_STACK_MIN may expand to a function call
+    size_t stacksize = PTHREAD_STACK_MIN; // Only small stack.
+    if (stacksize < 4096U) // But not too small: FreeBSD makes it 2k
+        stacksize = 4096U;
+    pthread_attr_setstacksize(&attrs, stacksize);
 #endif
     threadRunning = pthread_create(&detectionThreadId, &attrs, SignalDetectionThread, 0) == 0;
     pthread_attr_destroy(&attrs);
