Discussion:
PTHREAD_STACK_MIN
Patrick Welche
2014-08-14 23:30:40 UTC
Permalink
I just tried to compile xen, and the first problem I hit is that it makes
use of PTHREAD_STACK_MIN.

Tantalizingly, our /usr/include/limits.h says:

/* Not yet: PTHREAD_STACK_MIN */


http://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html suggests
that any positive value is possible:

Minimum size in bytes of thread stack storage. Minimum Acceptable Value: 0


According to pthread_attr_getstack(3):

The pthread_attr_setstacksize() function may additionally fail if:

[EINVAL] The specified stacksize is less than PTHREAD_STACK_MIN
or exceeds some system-imposed limit.

and pthread_attr_setstacksize returns EINVAL if
stacksize > _SC_THREAD_STACK_MIN (=59) as per /usr/include/sys/unistd.h.

Should PTHREAD_STACK_MIN be defined to 59?



Cheers,

Patrick
Joerg Sonnenberger
2014-08-14 23:48:55 UTC
Permalink
Post by Patrick Welche
and pthread_attr_setstacksize returns EINVAL if
stacksize > _SC_THREAD_STACK_MIN (=59) as per /usr/include/sys/unistd.h.
No, it returns EINVAL if stacksize < sysconf(_SC_THREAD_STACK_MIN).
Small difference. We map that to getpagesize(), but that's not a fixed
value on some platforms.

Joerg
Patrick Welche
2014-08-15 07:37:14 UTC
Permalink
Post by Joerg Sonnenberger
Post by Patrick Welche
and pthread_attr_setstacksize returns EINVAL if
stacksize > _SC_THREAD_STACK_MIN (=59) as per /usr/include/sys/unistd.h.
No, it returns EINVAL if stacksize < sysconf(_SC_THREAD_STACK_MIN).
Small difference. We map that to getpagesize(), but that's not a fixed
value on some platforms.
I thought "59 is rather small"...

So it sounds as though it is safe to use sysconf(_SC_THREAD_STACK_MIN)
instead of PTHREAD_STACK_MIN ? (They are meant to achieve the same thing?)

Cheers,

Patrick
Joerg Sonnenberger
2014-08-15 13:04:08 UTC
Permalink
Post by Patrick Welche
Post by Joerg Sonnenberger
Post by Patrick Welche
and pthread_attr_setstacksize returns EINVAL if
stacksize > _SC_THREAD_STACK_MIN (=59) as per /usr/include/sys/unistd.h.
No, it returns EINVAL if stacksize < sysconf(_SC_THREAD_STACK_MIN).
Small difference. We map that to getpagesize(), but that's not a fixed
value on some platforms.
I thought "59 is rather small"...
So it sounds as though it is safe to use sysconf(_SC_THREAD_STACK_MIN)
instead of PTHREAD_STACK_MIN ? (They are meant to achieve the same thing?)
Yes, it should be safe to use it. The main difference is that
PTHREAD_STACK_MIN must be a compile time constant.

Joerg

Loading...