I am trying to increase stacksize of pthreads using the following code snippet:
size_t newstacksz = 0xf000;
void * arg = 0;
int ret = pthread_attr_setstacksize(&attr, newstacksz);
if (ret == -1) {
std::cout << "Attempt to increase thread stack size failed, resorting to default" << endl;
ret = pthread_attr_setstacksize(&attr, 0); // minimum allowable
}
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); // system-wide contention
ret = pthread_create(&tid,&attr,thrfn,arg);
pthread_attr_destroy(&attr);
Can I get an estimate about maximum allowable stacksize per thread if I to create multiple worker threads?
pthreads doesn't have a notion of maximum stack size. So there's no way to ask pthread to give a thread the "maximum allowable" stack size. There's also no way to ask pthread for a recommended maximum allowable stack size for a known set of threads.
What a suitable (maximum?) stack size is for your particular application depends on so many things: machine, OS, available memory, expected load, expected stack consumption etc., so it's really no wonder pthreads can't tell you. I can't either.
You'll have to figure out, somehow, what the proper stack size is yourself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.