.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2012-05-03, Akihiro MOTOKI .\" .TH PTHREAD_ATTR_SETSTACK 3 2020\-06\-09 Linux "Linux Programmer's Manual" .SH 名前 pthread_attr_setstack, pthread_attr_getstack \- スレッド属性オブジェクトのスタック属性の設定/取得を行う .SH 書式 .nf \fB#include \fP .PP \fBint pthread_attr_setstack(pthread_attr_t *\fP\fIattr\fP\fB,\fP \fB void *\fP\fIstackaddr\fP\fB, size_t \fP\fIstacksize\fP\fB);\fP \fBint pthread_attr_getstack(const pthread_attr_t *\fP\fIattr\fP\fB,\fP \fB void **\fP\fIstackaddr\fP\fB, size_t *\fP\fIstacksize\fP\fB);\fP .PP \fI\-pthread\fP でコンパイルしてリンクする。 .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP .ad l \fBpthread_attr_getstack\fP(), \fBpthread_attr_setstack\fP(): .RS 4 _POSIX_C_SOURCE\ >=\ 200112L .RE .ad b .SH 説明 \fBpthread_attr_setstack\fP() 関数は、 \fIattr\fP が参照するスレッド属性オブジェクトのスタックアドレス属性と スタックサイズ属性をそれぞれ \fIstackaddr\fP と \fIstacksize\fP で 指定された値に設定する。 これらの属性により、スレッド属性オブジェクト \fIattr\fP を使って 作成されるスレッドが使用すべきスタックの位置とサイズが指定される。 .PP \fIstackaddr\fP は、呼び出し側で割り当てた、大きさが \fIstacksize\fP バイトの バッファー内の指定できる最小のアドレスバイトを指すべきである。 割り当てられたバッファーのページは読み書き両方が可能なページとなっている べきである。 .PP \fBpthread_attr_getstack\fP() 関数は、 スレッド属性オブジェクト \fIattr\fP のスタックアドレス属性と スタックサイズ属性をそれぞれ \fIstackaddr\fP と \fIstacksize\fP が 指すバッファーに入れて返す。 .SH 返り値 成功すると、これらの関数は 0 を返す。 エラーの場合、0 以外のエラー番号を返す。 .SH エラー \fBpthread_attr_setstack\fP() は以下のエラーで失敗する場合がある。 .TP \fBEINVAL\fP \fIstacksize\fP が \fBPTHREAD_STACK_MIN\fP (16384) よりも小さい。 システムによっては、 \fIstackaddr\fP か \fIstackaddr\ +\ stacksize\fP のアライメントが適切でない場合にも このエラーが発生する。 .PP POSIX.1 では エラー \fBEACCES\fP も規定されており、このエラーは \fIstackaddr\fP と \fIstacksize\fP で規定されるスタック領域に呼び出し側から読み書き両方のアクセスができない状況を表す。 .SH バージョン これらの関数は glibc バージョン 2.2 以降で提供されている。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw24 lb lb l l l. インターフェース 属性 値 T{ \fBpthread_attr_setstack\fP(), \fBpthread_attr_getstack\fP() T} Thread safety MT\-Safe .TE .SH 準拠 POSIX.1\-2001, POSIX.1\-2008. .SH 注意 これらの関数は、スレッドのスタックが特定の場所に配置されることを保証 しなければならないアプリケーションのために提供されている。 ほとんどのアプリケーションでは、このようなことは必要なく、 これらの関数を使うのは避けるべきである。 (アプリケーションが単にスタックサイズだけをデフォルトの値から変更する 必要がある場合には \fBpthread_attr_setstacksize\fP(3) を使うこと) .PP アプリケーションが \fBpthread_attr_setstack\fP() を利用する際には、 スタックの割り当てに責任を持つ必要がある。 \fBpthread_attr_setguardsize\fP(3) を使って設定された guard size の値は無視される。 必要と思われる場合は、アプリケーションが責任を持ってガード領域 (読み書 きが行われないように保護された 1 個かそれ以上のページ) の割り当てを行い、 スタックオーバーフローの可能性に対処するようにする必要がある。 .PP \fIstackaddr\fP に指定するアドレスは適切なアライメントとなっているべきである。 完全な移植性を持たせるためには、 ページ境界 (\fIsysconf(_SC_PAGESIZE)\fP) に揃えること。 割り当てには \fBposix_memalign\fP(3) を使うとよい。 たいていは、 \fIstacksize\fP はシステムのページサイズの倍数とすべきである。 .PP 一つの \fIattr\fP を使って複数のスレッドを作成する場合、 \fBpthread_create\fP(3) の次の呼び出しを行う前に、 呼び出し側でスタックアドレス属性を変更しなければならない。 さもなければ、複数のスレッドがスタックとして同じメモリー領域を 使おうとするため、訳の分からない状況が発生してしまう。 .SH 例 \fBpthread_attr_init\fP(3) を参照。 .SH 関連項目 .ad l .nh \fBmmap\fP(2), \fBmprotect\fP(2), \fBposix_memalign\fP(3), \fBpthread_attr_init\fP(3), \fBpthread_attr_setguardsize\fP(3), \fBpthread_attr_setstackaddr\fP(3), \fBpthread_attr_setstacksize\fP(3), \fBpthread_create\fP(3), \fBpthreads\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。