標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
POSIX.4a |
両方 | POSIX(ON) |
#define _OPEN_THREADS
#include <pthread.h>
int pthread_attr_init(pthread_attr_t *attr);
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_attr_init(pthread_attr_t *attr);
スレッド属性オブジェクトを使用して、アプリケーションのスレッドの特性を 管理できます。これは、生成時にスレッドに使用される値の集合を定義します。スレッド属性オブジェクトを確立すると、各スレッドごとに特性を定義しないで、同じ一連の特性をもつ多数のスレッドを作成できます。複数のスレッド属性オブジェクトを定義できます。スレッドの優先順位はすべて同じです。
正常に実行された場合、pthread_attr_init() は 0 を戻します。
Single UNIX Specification、バージョン 3 の特殊な動作: 正常に実行されなかった場合、pthread_attr_init() はエラーを示すエラー番号を戻します。
⁄* CELEBP10 *⁄
#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;
pthread_attr_t attr;
pthread_t thid;
rc = pthread_attr_init(&attr);
if (rc == -1) {
perror("error in pthread_attr_init");
exit(1);
}
rc = pthread_create(&thid, &attr, thread1, NULL);
if (rc == -1) {
perror("error in pthread_create");
exit(2);
}
rc = pthread_join(thid, (void *)&stat);
exit(0);
}