Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an example taken from the <a href="http://www.gnu.org/s/pth/" rel="nofollow">GnuPth</a>(<code>pth_lib.c</code>) user-level threading library, which shows the implementation of the <code>exit</code> and <code>join</code> functions, respectively. I <strong>simplified</strong> the code to highlight the return value handling.</p> <pre><code>void pth_exit(void *value) { pth_debug2("pth_exit: marking thread \"%s\" as dead", pth_current-&gt;name); /* the main thread is special, because its termination would terminate the whole process, so we have to delay its termination until it is really the last thread */ /* execute cleanups */ /* * Now mark the current thread as dead, explicitly switch into the * scheduler and let it reap the current thread structure; we can't * free it here, or we'd be running on a stack which malloc() regards * as free memory, which would be a somewhat perilous situation. */ pth_current-&gt;join_arg = value; pth_current-&gt;state = PTH_STATE_DEAD; pth_debug2("pth_exit: switching from thread \"%s\" to scheduler", pth_current-&gt;name); //return (for ever) to the scheduler } </code></pre> <p>and the corresponding <code>pth_join</code>:</p> <pre><code>/* waits for the termination of the specified thread */ int pth_join(pth_t tid, void **value) { //Validate thread situation. //wait until thread death //save returned value for the caller if (value != NULL) *value = tid-&gt;join_arg; //remove thread from the thread queue //free its memory space return TRUE; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload