I'm using QtConcurrent/QThreadPool and it is creating threads with a stack-size that is too small on Mac OS X 10.8 (512kB) but fine on CentOS 5.9 (10MB).
I'm hoping there is a workaround where I can set some process-wide default for new threads' stack size. I only care about POSIX-like systems (Mac and Linux) and not Windows for the time being.
My question is how do I set the default stack-size for new QThreadPool threads either from within the program or via an environment variable or other means prior to running the program?
Answers for achieving the effect by setting the default for threads created by pthread_create
will also be useful.
Where I'm at with my attempts to solve this problem:
My hunch is that Qt is using pthreads under the hood and that if I can change the default stack-size for pthreads my problem might be solved.
The pthread documentation says:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);
DESCRIPTION
The pthread_create() function is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes are used. etc...
I know how to get the default value:
size_t stacksize;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_getstacksize (&attr, &stacksize);
But I have not found a way to set the default value - only to set the size by passing a pthread_attr_t
to pthread_create
.
Is there a way to set the default?
Is there some environment variable or other means to influence the default?