diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/c/thread%2Fthrd_yield.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/c/thread%2Fthrd_yield.html')
| -rw-r--r-- | devdocs/c/thread%2Fthrd_yield.html | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/devdocs/c/thread%2Fthrd_yield.html b/devdocs/c/thread%2Fthrd_yield.html deleted file mode 100644 index 7eb8bcad..00000000 --- a/devdocs/c/thread%2Fthrd_yield.html +++ /dev/null @@ -1,52 +0,0 @@ - <h1 id="firstHeading" class="firstHeading">thrd_yield</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><threads.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">void thrd_yield(void);</pre> -</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <p>Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run.</p> -<h3 id="Parameters"> Parameters</h3> <p>(none)</p> -<h3 id="Return_value"> Return value</h3> <p>(none)</p> -<h3 id="Notes"> Notes</h3> <p>The exact behavior of this function depends on the implementation, in particular on the mechanics of the OS scheduler in use and the state of the system. For example, a first-in-first-out realtime scheduler (<code>SCHED_FIFO</code> in Linux) would suspend the current thread and put it on the back of the queue of the same-priority threads that are ready to run (and if there are no other threads at the same priority, <code>yield</code> has no effect).</p> -<p>The POSIX equivalent of this function is <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html"><code>sched_yield</code></a>.</p> -<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> -#include <time.h> -#include <threads.h> - -// utility function: difference between timespecs in microseconds -double usdiff(struct timespec s, struct timespec e) -{ - double sdiff = difftime(e.tv_sec, s.tv_sec); - long nsdiff = e.tv_nsec - s.tv_nsec; - if(nsdiff < 0) return 1000000*(sdiff-1) + (1000000000L+nsdiff)/1000.0; - else return 1000000*(sdiff) + nsdiff/1000.0; -} - -// busy wait while yielding -void sleep_100us() -{ - struct timespec start, end; - timespec_get(&start, TIME_UTC); - do { - thrd_yield(); - timespec_get(&end, TIME_UTC); - } while(usdiff(start, end) < 100.0); -} - -int main() -{ - struct timespec start, end; - timespec_get(&start, TIME_UTC); - sleep_100us(); - timespec_get(&end, TIME_UTC); - printf("Waited for %.3f us\n", usdiff(start, end)); -}</pre></div> <p>Possible output:</p> -<div class="text source-text"><pre data-language="c">Waited for 100.344 us</pre></div> </div> <h3 id="References"> References</h3> <ul> -<li> C17 standard (ISO/IEC 9899:2018): </li> -<ul><li> 7.26.5.8 The thrd_yield function (p: 281) </li></ul> -<li> C11 standard (ISO/IEC 9899:2011): </li> -<ul><li> 7.26.5.8 The thrd_yield function (p: 385) </li></ul> -</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="thrd_sleep" title="c/thread/thrd sleep"> <span class="t-lines"><span>thrd_sleep</span></span></a></div> -<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> suspends execution of the calling thread for the given period of time <br> <span class="t-mark">(function)</span> </td> -</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/thread/yield" title="cpp/thread/yield">C++ documentation</a></span> for <code>yield</code> </td> -</tr> </table> <div class="_attribution"> - <p class="_attribution-p"> - © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> - <a href="https://en.cppreference.com/w/c/thread/thrd_yield" class="_attribution-link">https://en.cppreference.com/w/c/thread/thrd_yield</a> - </p> -</div> |
