⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makecontext.html

📁 posix标准英文,html格式
💻 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-2004 IEEE and The Open Group, All Rights Reserved --><title>makecontext</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="makecontext"></a> <a name="tag_03_356"></a><!-- makecontext --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_356_01"></a>NAME</h4><blockquote>makecontext, swapcontext - manipulate user contexts</blockquote><h4><a name="tag_03_356_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('OB XSI')">OB XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/ucontext.h.html">ucontext.h</a>&gt;<br><br> void makecontext(ucontext_t *</tt><i>ucp</i><tt>, void (*</tt><i>func</i><tt>)(),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</tt> <i>argc</i><tt>, ...);<br> int swapcontext(ucontext_t *restrict</tt> <i>oucp</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const ucontext_t *restrict</tt> <i>ucp</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_356_03"></a>DESCRIPTION</h4><blockquote><p>The <i>makecontext</i>() function shall modify the context specified by <i>ucp</i>, which has been initialized using <a href="../functions/getcontext.html"><i>getcontext</i>()</a>. When this context is resumed using <i>swapcontext</i>() or <a href="../functions/setcontext.html"><i>setcontext</i>()</a>, program execution shall continue by calling <i>func</i>, passing it thearguments that follow <i>argc</i> in the <i>makecontext</i>() call.</p><p>Before a call is made to <i>makecontext</i>(), the application shall ensure that the context being modified has a stackallocated for it. The application shall ensure that the value of <i>argc</i> matches the number of arguments of type <b>int</b>passed to <i>func</i>; otherwise, the behavior is undefined.</p><p>The <i>uc_link</i> member is used to determine the context that shall be resumed when the context being modified by<i>makecontext</i>() returns. The application shall ensure that the <i>uc_link</i> member is initialized prior to the call to<i>makecontext</i>().</p><p>The <i>swapcontext</i>() function shall save the current context in the context structure pointed to by <i>oucp</i> and shallset the context to the context structure pointed to by <i>ucp</i>.</p></blockquote><h4><a name="tag_03_356_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>swapcontext</i>() shall return 0. Otherwise, -1 shall be returned and <i>errno</i> set toindicate the error.</p></blockquote><h4><a name="tag_03_356_05"></a>ERRORS</h4><blockquote><p>The <i>swapcontext</i>() function shall fail if:</p><dl compact><dt>[ENOMEM]</dt><dd>The <i>ucp</i> argument does not have enough stack left to complete the operation.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_356_06"></a>EXAMPLES</h4><blockquote><p>The following example illustrates the use of <i>makecontext</i>():</p><pre><tt>#include &lt;stdio.h&gt;#include &lt;ucontext.h&gt;<br>static ucontext_t ctx[3];<br>static voidf1 (void){    puts("start f1");    swapcontext(&amp;ctx[1], &amp;ctx[2]);    puts("finish f1");}<br>static voidf2 (void){    puts("start f2");    swapcontext(&amp;ctx[2], &amp;ctx[1]);    puts("finish f2");}<br>intmain (void){    char st1[8192];    char st2[8192];<br>    getcontext(&amp;ctx[1]);    ctx[1].uc_stack.ss_sp = st1;    ctx[1].uc_stack.ss_size = sizeof st1;    ctx[1].uc_link = &amp;ctx[0];    makecontext(&amp;ctx[1], f1, 0);<br>    getcontext(&amp;ctx[2]);    ctx[2].uc_stack.ss_sp = st2;    ctx[2].uc_stack.ss_size = sizeof st2;    ctx[2].uc_link = &amp;ctx[1];    makecontext(&amp;ctx[2], f2, 0);<br>    swapcontext(&amp;ctx[0], &amp;ctx[2]);    return 0;}</tt></pre></blockquote><h4><a name="tag_03_356_07"></a>APPLICATION USAGE</h4><blockquote><p>The obsolescent functions <a href="../functions/getcontext.html"><i>getcontext</i>()</a>, <i>makecontext</i>(), and<i>swapcontext</i>() can be replaced using POSIX threads functions.</p></blockquote><h4><a name="tag_03_356_08"></a>RATIONALE</h4><blockquote><p>With the incorporation of the ISO/IEC&nbsp;9899:1999 standard into this specification it was found that the ISO&nbsp;C standard(Subclause 6.11.6) specifies that the use of function declarators with empty parentheses is an obsolescent feature. Therefore,using the function prototype:</p><pre><tt>void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...);</tt></pre><p>is making use of an obsolescent feature of the ISO&nbsp;C standard. Therefore, a strictly conforming POSIX application cannotuse this form. Therefore, use of <a href="../functions/getcontext.html"><i>getcontext</i>()</a>, <i>makecontext</i>(), and<i>swapcontext</i>() is marked obsolescent.</p><p>There is no way in the ISO&nbsp;C standard to specify a non-obsolescent function prototype indicating that a function will becalled with an arbitrary number (including zero) of arguments of arbitrary types (including integers, pointers to data, pointers tofunctions, and composite types).</p><p>Replacing <i>makecontext</i>() with a number of ISO&nbsp;C standard-compatible functions handing various numbers and types ofarguments would have forced all existing uses of <i>makecontext</i>() to be rewritten for little or no gain. There are very fewapplications today that use the <a href="../functions/*context.html"><i>*context</i>()</a> routines. Those that do use them arealmost always using them to implement co-routines. By maintaining the XSH, Issue 5 specification for <i>makecontext</i>(), existingapplications will continue to work, although they won't be able to be classified as strictly conforming applications.</p><p>There is no way in the ISO&nbsp;C standard (without using obsolescent behavior) to specify functionality that was standard,strictly conforming behavior in the XSH, Issue 5 specification using the ISO&nbsp;C standard. Threads can be used to implement thefunctionality provided by <i>makecontext</i>(), <a href="../functions/getcontext.html"><i>getcontext</i>()</a>, and<i>swapcontext</i>() but they are more complex to use. It was felt inventing new ISO&nbsp;C standard-compatible interfaces thatdescribe what can be done with the XSH, Issue 5 functions and then converting applications to use them would cause more difficultythan just converting applications that use them to use threads instead.</p></blockquote><h4><a name="tag_03_356_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_356_10"></a>SEE ALSO</h4><blockquote><p><a href="exit.html"><i>exit</i>()</a>, <a href="getcontext.html"><i>getcontext</i>()</a>, <a href="sigaction.html"><i>sigaction</i>()</a>, <a href="sigprocmask.html"><i>sigprocmask</i>()</a>, the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/ucontext.h.html"><i>&lt;ucontext.h&gt;</i></a></p></blockquote><h4><a name="tag_03_356_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_356_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p><p>In the ERRORS section, the description of [ENOMEM] is changed to apply to <i>swapcontext</i>() only.</p></blockquote><h4><a name="tag_03_356_13"></a>Issue 6</h4><blockquote><p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p><p>The <b>restrict</b> keyword is added to the <i>swapcontext</i>() prototype for alignment with the ISO/IEC&nbsp;9899:1999standard.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XSH/TC1/D6/33 is applied, clarifying that the arguments passed to <i>func</i>are of type <b>int</b>.</p><p>IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;2-2004, item XSH/TC2/D6/57 is applied, obsoleting the functions and giving advice on thealternatives. Changes are made to the SYNOPSIS, APPLICATION USAGE, and RATIONALE sections.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; 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 + -