📄 pthread_attr_getguardsize.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>pthread_attr_getguardsize</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="pthread_attr_getguardsize"></a> <a name="tag_03_489"></a><!-- pthread_attr_getguardsize --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_489_01"></a>NAME</h4><blockquote>pthread_attr_getguardsize, pthread_attr_setguardsize - get and set the thread guardsize attribute</blockquote><h4><a name="tag_03_489_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/pthread.h.html">pthread.h</a>><br><br> int pthread_attr_getguardsize(const pthread_attr_t *restrict</tt> <i>attr</i><tt>,<br> size_t *restrict</tt> <i>guardsize</i><tt>);<br> int pthread_attr_setguardsize(pthread_attr_t</tt> <i>*attr</i><tt>,<br> size_t</tt> <i>guardsize</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]"border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_489_03"></a>DESCRIPTION</h4><blockquote><p>The <i>pthread_attr_getguardsize</i>() function shall get the <i>guardsize</i> attribute in the <i>attr</i> object. Thisattribute shall be returned in the <i>guardsize</i> parameter.</p><p>The <i>pthread_attr_setguardsize</i>() function shall set the <i>guardsize</i> attribute in the <i>attr</i> object. The newvalue of this attribute shall be obtained from the <i>guardsize</i> parameter. If <i>guardsize</i> is zero, a guard area shall notbe provided for threads created with <i>attr</i>. If <i>guardsize</i> is greater than zero, a guard area of at least size<i>guardsize</i> bytes shall be provided for each thread created with <i>attr</i>.</p><p>The <i>guardsize</i> attribute controls the size of the guard area for the created thread's stack. The <i>guardsize</i>attribute provides protection against overflow of the stack pointer. If a thread's stack is created with guard protection, theimplementation allocates extra memory at the overflow end of the stack as a buffer against stack overflow of the stack pointer. Ifan application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).</p><p>A conforming implementation may round up the value contained in <i>guardsize</i> to a multiple of the configurable systemvariable {PAGESIZE} (see <a href="../basedefs/sys/mman.h.html"><i><sys/mman.h></i></a>). If an implementation rounds up thevalue of <i>guardsize</i> to a multiple of {PAGESIZE}, a call to <i>pthread_attr_getguardsize</i>() specifying <i>attr</i> shallstore in the <i>guardsize</i> parameter the guard size specified by the previous <i>pthread_attr_setguardsize</i>() functioncall.</p><p>The default value of the <i>guardsize</i> attribute is {PAGESIZE} bytes. The actual value of {PAGESIZE} isimplementation-defined.</p><p>If the <i>stackaddr</i> or <i>stack</i> attribute has been set (that is, the caller is allocating and managing its own threadstacks), the <i>guardsize</i> attribute shall be ignored and no protection shall be provided by the implementation. It is theresponsibility of the application to manage stack overflow along with stack allocation and management in this case.</p></blockquote><h4><a name="tag_03_489_04"></a>RETURN VALUE</h4><blockquote><p>If successful, the <i>pthread_attr_getguardsize</i>() and <i>pthread_attr_setguardsize</i>() functions shall return zero;otherwise, an error number shall be returned to indicate the error.</p></blockquote><h4><a name="tag_03_489_05"></a>ERRORS</h4><blockquote><p>The <i>pthread_attr_getguardsize</i>() and <i>pthread_attr_setguardsize</i>() functions shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The attribute <i>attr</i> is invalid.</dd><dt>[EINVAL]</dt><dd>The parameter <i>guardsize</i> is invalid.</dd></dl><p>These functions shall not return an error code of [EINTR].</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_489_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_489_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_489_08"></a>RATIONALE</h4><blockquote><p>The <i>guardsize</i> attribute is provided to the application for two reasons:</p><ol><li><p>Overflow protection can potentially result in wasted system resources. An application that creates a large number of threads,and which knows its threads never overflow their stack, can save system resources by turning off guard areas.</p></li><li><p>When threads allocate large data structures on the stack, large guard areas may be needed to detect stack overflow.</p></li></ol></blockquote><h4><a name="tag_03_489_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_489_10"></a>SEE ALSO</h4><blockquote><p>The Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/pthread.h.html"><i><pthread.h></i></a>, <a href="../basedefs/sys/mman.h.html"><i><sys/mman.h></i></a></p></blockquote><h4><a name="tag_03_489_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5.</p></blockquote><h4><a name="tag_03_489_12"></a>Issue 6</h4><blockquote><p>In the ERRORS section, a third [EINVAL] error condition is removed as it is covered by the second error condition.</p><p>The <b>restrict</b> keyword is added to the <i>pthread_attr_getguardsize</i>() prototype for alignment with theISO/IEC 9899:1999 standard.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -