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

📄 pthread.html

📁 多线程库
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>pthread Class</TITLE></HEAD><BODY bgcolor="#ffffff"><H1>pthread Class Reference</H1><p>[<A HREF="index.html">threads Index</A>] [<A HREF="heir.html">threads Hierarchy</A>]</p><HR><P>Abstract class for threads.   <a href="#short">More...</a></P><P><code>	#include &lt;<a href="-usr-local-include-thread-h.html">/usr/local/include/thread.h</a>&gt;</code></P><H2>Public Members</H2><UL><LI>enum <b><a name="ref0">cancel_state</a></b> {    cancel_enable,    cancel_disable  }</LI><LI>enum <b><a name="ref1">cancel_type</a></b> {    cancel_deferred,    cancel_asynchronous  }</LI><LI>enum <b><a name="ref2">jumps</a></b> {    signal_jmp,    cancel_jmp  }</LI><LI>enum <b><a name="ref3">booleans</a></b> {    set_terminated,    set_detached,    set_exited,    set_canceled,    set_private  }</LI><LI><b><a name="ref4">pthread</a></b> () </LI><LI><b><a name="ref5">pthread</a></b> (void *) </LI><LI><b><a name="ref6">pthread</a></b> (int) </LI><LI>virtual <b><a name="ref7">~pthread</a></b> () </LI><LI>virtual int <b><a href="#ref8">thread</a></b> (void *) </LI><LI>void *<b><a href="#ref9">retval</a></b> () </LI><LI>int  <b><a href="#ref10">joining</a></b> () </LI><LI>int  <b><a href="#ref11">gerrno</a></b> () </LI><LI>int  <b><a href="#ref12">id</a></b> () </LI><LI>int  <b><a href="#ref13">signal</a></b> () </LI><LI>int  <b><a href="#ref14">signal</a></b> (int) </LI><LI>bool <b><a href="#ref15">canceled</a></b> () </LI><LI>bool <b><a href="#ref16">detached</a></b> () </LI><LI>bool <b><a href="#ref17">joinable</a></b> () </LI><LI>bool <b><a href="#ref18">terminated</a></b> () </LI><LI>bool <b><a href="#ref19">exited</a></b> () </LI><LI>cancel_state <b><a href="#ref20">cancelstate</a></b> () </LI><LI>cancel_type <b><a href="#ref21">canceltype</a></b> () </LI><LI>int <b><a href="#ref22">joining</a></b> (int s) </LI><LI>void <b><a href="#ref23">set</a></b> (cancel_state s) </LI><LI>void <b><a href="#ref24">set</a></b> (cancel_type t) </LI><LI>void <b><a href="#ref25">set</a></b> (jumps, sigjmp_buf *) </LI><LI>void <b><a href="#ref26">set</a></b> (booleans, bool) </LI><LI>void <b><a href="#ref27">cancel</a></b> () </LI><LI>void <b><a href="#ref28">suspend</a></b> () </LI><LI>void <b><a href="#ref29">suspend_with_cancelation</a></b> () </LI><LI>void <b><a href="#ref30">restart</a></b> () </LI><LI>void <b><a href="#ref31">jump</a></b> (jumps) </LI><LI>void <b><a href="#ref32">exit</a></b> (void *) </LI><LI>void <b><a href="#ref33">exit</a></b> (int) </LI><LI>void <b><a href="#ref34">exit</a></b> () </LI><LI>int <b><a href="#ref35">retcode</a></b> () </LI><LI>bool <b><a href="#ref36">running</a></b> () </LI><LI>int <b><a href="#ref37">join</a></b> () </LI><LI>static void <b><a href="#ref38">set_project</a></b> (const char *) </LI><LI>static void <b><a href="#ref39">set_permission</a></b> (int) </LI><LI>pthread&amp; <b><a name="ref40">operator=</a></b> (cancel_state s) </LI><LI>pthread&amp; <b><a name="ref41">operator=</a></b> (cancel_type t) </LI></UL><HR><H2><a name="short">Detailed Description</a></H2><P> Threads, are cloned processes that share the same memory for reading and writing.  This is a primitive and needs to be a superclass to any specific needs for threaded execution.</p><p></P><HR><H2>virtual int <a name="ref8"></a><a name="thread">thread</a>(void *)  </H2><p> An abstract definition of the method, that will be run as a different process by this class.  This is the starting point, of the new process.</p><p> In creating a new process, it should be taken care off that the process itself, is starting its execution at the same time as the construction is initializing class variables.  This may be unwanted, and to have a process wait for the initialization to finish, the following method can be used.</p><p> <pre></p><p> #include <thread.h></p><p> class mythread : public pthread { private:   semaphore run_away;   string something;</p><p> public:   mythread()   {     something = "This has been initialized";     run_away.post();   // last instruction in constructor.   }   ~mythread()   {      // TODO: destroy variables.   }</p><p>   int thread(void *)   {      run_away.wait();      // Now, the process is synchronized to run after      // the initialisation has finished.   } };</p><p> </pre></p><p> The above mechanism, can both be seen as a quirk, and as a drawback. In most cases, the thread doesn't need the variables in its class, so forcing the thread to wait until the constructor has finished isn't necessary... and perhaps even unwanted.</p><p></p><dl><dt><b>Parameters</b>:<dd><table width="100%" border="0"><tr><td align="left" valign="top">any</td><td align="left" valign="top">The process will receive a parameter, whose type is only known internally.</td></tr></table></dl><dl><dt><b>Returns</b>:<dd>Actually, nothing is returned here.  See pthread::retval how to acquire return values.</dl><H2>void *<a name="ref9"></a><a name="retval">retval</a>()  </H2><p> This method allows access to the value returned by the process, if it has returned, that is.  Otherwise, it contains an undefined value.</p><p></p><dl><dt><b>Returns</b>:<dd>A pointer, that the thread can register as a return value.</dl><H2>int  <a name="ref10"></a><a name="joining">joining</a>()  </H2><p> This method defines, wether the thread is joining with another thread.  The return value, is either the process id of the thread that is to be joined with, or 0 which indicates that it is not being joined with anyone.</p><p></p><dl><dt><b>Returns</b>:<dd>the pid of the process to join with.</dl><H2>int  <a name="ref11"></a><a name="gerrno">gerrno</a>()  </H2><p> If an error has occurred, during the process, it will be locally stored and can be retrieved by this method.  Note however, that it is upon the user to make sure that his thread sets this value with the <a href="pthread.html#error">error</a> function.</p><p></p><dl><dt><b>Returns</b>:<dd>The last errorvalue registered.</dl><H2>int  <a name="ref12"></a><a name="id">id</a>()  </H2><p> Each thread has its own process id, and even though it is possible with the clone system to clone the process id as well, it is not done within this thread package.</p><p></p><dl><dt><b>Returns</b>:<dd>the pid of this thread.</dl><H2>int  <a name="ref13"></a><a name="signal">signal</a>()  </H2><p> Each time a thread receives a signal, it stores the signal number locally so that parent threads can view or debug its status.</p><p></p><dl><dt><b>Returns</b>:<dd>Last signal received by the thread.</dl><H2>int  <a name="ref14"></a><a name="signal">signal</a>(int)  </H2><p> This is a convenience function, provided to simplify the use of sending signals to a thread.  If the user has access to the thread class, he can use this method to signal the thread instead of the system kill function.</p><p></p><dl><dt><b>Returns</b>:<dd>Last signal received by the thread.</dl><H2>bool <a name="ref15"></a><a name="canceled">canceled</a>()  </H2><p> A running thread can terminate in several ways, it can terminate by returning or exiting from the thread, or it can be canceled from inside or from an outside source. This function reports if the thread was canceled.</p><p></p><dl><dt><b>Returns</b>:<dd>True if the thread has been canceled.</dl>

⌨️ 快捷键说明

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