In case of certain libc implementations (such as musl libc)
that have a really small default pthread stack size.

Will reference this discussion:
http://patchwork.ozlabs.org/patch/572340/

Thanks to Robert McKay for reporting and Russel and Ben
for reviewing.

Signed-off-by: Russell Bryant <russ...@ovn.org>
Signed-off-by: Ben Pfaff <b...@ovn.org>
Signed-off-by: Robert McKay <rob...@mckay.com>
Signed-off-by: Alexandru Ardelean <ardeleana...@gmail.com>
---
 lib/ovs-thread.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 6ebda07..b6684d4 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -345,8 +345,11 @@ ovsthread_wrapper(void *aux_)
 pthread_t
 ovs_thread_create(const char *name, void *(*start)(void *), void *arg)
 {
+#define OVS_MIN_THREAD_STACK_SIZE    (512 * 1024)
     struct ovsthread_aux *aux;
     pthread_t thread;
+    pthread_attr_t attr;
+    size_t stacksize;
     int error;
 
     forbid_forking("multiple threads exist");
@@ -358,10 +361,29 @@ ovs_thread_create(const char *name, void *(*start)(void 
*), void *arg)
     aux->arg = arg;
     ovs_strlcpy(aux->name, name, sizeof aux->name);
 
+    pthread_attr_init(&attr);
+    error = pthread_attr_getstacksize(&attr, &stacksize);
+    if (error) {
+        free(aux);
+        ovs_abort(error, "pthread_attr_getstacksize failed");
+        goto out;
+    }
+
+    if (stacksize < OVS_MIN_THREAD_STACK_SIZE) {
+        error = pthread_attr_setstacksize(&attr, OVS_MIN_THREAD_STACK_SIZE);
+        if (error) {
+            free(aux);
+            ovs_abort(error, "pthread_attr_setstacksize failed");
+            goto out;
+        }
+    }
+
     error = pthread_create(&thread, NULL, ovsthread_wrapper, aux);
     if (error) {
         ovs_abort(error, "pthread_create failed");
     }
+out:
+    pthread_attr_destroy(&attr);
     return thread;
 }
 
-- 
2.1.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to