]> git.sesse.net Git - vlc/commitdiff
Support for (compile-time) custom stack size
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 13 Sep 2008 10:21:08 +0000 (13:21 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 13 Sep 2008 10:21:08 +0000 (13:21 +0300)
src/misc/threads.c

index 7e405c303719606c2681e15b031d516723d4000c..6d2984547cf3e5cf056bff6edd23129ee13b6999 100644 (file)
@@ -689,6 +689,25 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
         pthread_attr_setschedparam (&attr, &sp);
     }
 
+    /* The thread stack size.
+     * The lower the value, the less address space per thread, the highest
+     * maximum simultaneous threads per process. Too low values will cause
+     * stack overflows and weird crashes. Set with caution. Also keep in mind
+     * that 64-bits platforms consume more stack than 32-bits one.
+     *
+     * Thanks to on-demand paging, thread stack size only affects address space
+     * consumption. In terms of memory, threads only use what they need
+     * (rounded up to the page boundary).
+     *
+     * For example, on Linux i386, the default is 2 mega-bytes, which supports
+     * about 320 threads per processes. */
+#define VLC_STACKSIZE (128 * sizeof (void *) * 1024)
+
+#ifdef VLC_STACKSIZE
+    ret = pthread_attr_setstacksize (&attr, VLC_STACKSIZE);
+    assert (ret == 0); /* fails iif VLC_STACKSIZE is invalid */
+#endif
+
     ret = pthread_create (p_handle, &attr, entry, data);
     pthread_sigmask (SIG_SETMASK, &oldset, NULL);
     pthread_attr_destroy (&attr);