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

📄 kernel-thread-termination.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Thread termination</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="The eCos Kernel"HREF="kernel.html"><LINKREL="PREVIOUS"TITLE="Thread control"HREF="kernel-thread-control.html"><LINKREL="NEXT"TITLE="Thread priorities"HREF="kernel-thread-priorities.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="kernel-thread-control.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="kernel-thread-priorities.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="KERNEL-THREAD-TERMINATION">Thread termination</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN560"></A><H2>Name</H2>cyg_thread_exit, cyg_thread_kill, cyg_thread_delete&nbsp;--&nbsp;Allow threads to terminate</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN565"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN566"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/kernel/kapi.h&gt;        </PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">void cyg_thread_exit</CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_thread_kill</CODE>(cyg_handle_t thread);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_thread_delete</CODE>(cyg_handle_t thread);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN582"></A><H2>Description</H2><P>In many embedded systems the various threads are allocated statically,created during initialization, and never need to terminate. Thisavoids any need for dynamic memory allocation or other resourcemanagement facilities. However if a given application does have arequirement that some threads be created dynamically, must terminate,and their resources such as the stack be reclaimed, then the kernelprovides the functions <TTCLASS="FUNCTION">cyg_thread_exit</TT>,<TTCLASS="FUNCTION">cyg_thread_kill</TT>, and<TTCLASS="FUNCTION">cyg_thread_delete</TT>.      </P><P><TTCLASS="FUNCTION">cyg_thread_exit</TT> allows a thread to terminateitself, thus ensuring that it will not be run again by the scheduler.However the <SPANCLASS="STRUCTNAME">cyg_thread</SPAN> data structure passedto <TTCLASS="FUNCTION">cyg_thread_create</TT> remains in use, and thehandle returned by <TTCLASS="FUNCTION">cyg_thread_create</TT> remainsvalid. This allows other threads to perform certain operations on theterminated thread, for example to determine its stack usage via<TTCLASS="FUNCTION">cyg_thread_measure_stack_usage</TT>. When the handleand <SPANCLASS="STRUCTNAME">cyg_thread</SPAN> structure are no longerrequired, <TTCLASS="FUNCTION">cyg_thread_delete</TT> should be called torelease these resources. If the stack was dynamically allocated thenthis should not be freed until after the call to<TTCLASS="FUNCTION">cyg_thread_delete</TT>.      </P><P>Alternatively, one thread may use <TTCLASS="FUNCTION">cyg_thread_kill</TT>on another This has much the same effect as the affected threadcalling <TTCLASS="FUNCTION">cyg_thread_exit</TT>. However killing a threadis generally rather dangerous because no attempt is made to unlock anysynchronization primitives currently owned by that thread or releaseany other resources that thread may have claimed. Therefore use ofthis function should be avoided, and<TTCLASS="FUNCTION">cyg_thread_exit</TT> is preferred.<TTCLASS="FUNCTION">cyg_thread_kill</TT> cannot be used by a thread tokill itself.      </P><P><TTCLASS="FUNCTION">cyg_thread_delete</TT> should be used on a threadafter it has exited and is no longer required. After this call thethread handle is no longer valid, and both the<SPANCLASS="STRUCTNAME">cyg_thread</SPAN> structure and the thread stack canbe re-used or freed. If <TTCLASS="FUNCTION">cyg_thread_delete</TT> isinvoked on a thread that is still running then there is an implicitcall to <TTCLASS="FUNCTION">cyg_thread_kill</TT>.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-THREAD-TERMINATION-CONTEXT"></A><H2>Valid contexts</H2><P><TTCLASS="FUNCTION">cyg_thread_exit</TT>,<TTCLASS="FUNCTION">cyg_thread_kill</TT> and<TTCLASS="FUNCTION">cyg_thread_delete</TT> can only be called from threadcontext.       </P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="kernel-thread-control.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="kernel-thread-priorities.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Thread control</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="kernel.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Thread priorities</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -