標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
POSIX.4a |
両方 | POSIX(ON) |
#define _OPEN_THREADS
#include <pthread.h>
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
スレッド属性オブジェクト attr の スタック・サイズ (バイト数) を設定します。stacksize は初期スタック・サイズです。他のスタック特性 (スタック 増分サイズなど) は、STACK64/THREADSTACK64 ランタイム・オプションから 継承されます。
スレッド属性オブジェクトを使用して、アプリケーションのスレッドの特性を 管理できます。これは、生成時にスレッドに使用される値の集合を定義します。スレッド属性オブジェクトを確立すると、各スレッドごとに特性を定義しないで、同じ一連の特性をもつ多数のスレッドを作成できます。複数のスレッド属性オブジェクトを定義できます。
正常に実行された場合、pthread_attr_setstacksize() は 0 を戻します。
正常に実行されなかった場合、pthread_attr_setstacksize() は -1 を戻します。
Single UNIX Specification、バージョン 3 の特殊な動作
正常に実行されなかった場合、pthread_attr_setstacksize() はエラーを示すエラー番号を戻します。
⁄* CELEBP12 *⁄
#define _OPEN_THREADS
#include <stdio.h>
#include <pthread.h>
void *thread1(void *arg)
{
printf("hello from the thread¥n");
pthread_exit(NULL);
}
int main()
{
int rc, stat;
size_t s1;
pthread_attr_t attr;
pthread_t thid;
rc = pthread_attr_init(&attr);
if (rc == -1) {
perror("error in pthread_attr_init");
exit(1);
}
s1 = 4096;
rc = pthread_attr_setstacksize(&attr, s1);
if (rc == -1) {
perror("error in pthread_attr_setstacksize");
exit(2);
}
rc = pthread_create(&thid, &attr, thread1, NULL);
if (rc == -1) {
perror("error in pthread_create");
exit(3);
}
rc = pthread_join(thid, (void *)&stat);
exit(0);
}