{{Short description|Concept in multithreading}} In computer science, '''yield''' is an action that occurs in a computer program during multithreading, of forcing a processor to relinquish control of the current running thread, and sending it to the end of the running queue, of the same scheduling priority.
== Examples == Different programming languages implement yielding in various ways.
*<code>pthread_yield()</code> in the language C, a low level implementation, provided by POSIX Threads<ref>{{cite web|title=pthread_yield|website=IBM |url=https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/ptyield.htm}}</ref> *<code>std::this_thread::yield()</code> in the language C++, introduced in C++11. * The ''Yield method'' is provided in various object-oriented programming languages with multithreading support, such as C# and Java.<ref>{{cite web|url=http://www.javamex.com/tutorials/threads/yield.shtml|title=Thread.yield|publisher=Javamex|access-date=24 June 2011}}</ref> OOP languages generally provide class abstractions for thread objects. *<code>yield</code> in Kotlin *<code>sched_yield()</code> in the C standard library, which causes the calling thread to relinquish the CPU.<ref>{{Cite web |title=sched_yield(2) - Linux manual page |url=https://man7.org/linux/man-pages/man2/sched_yield.2.html |access-date=2025-06-02 |website=man7.org}}</ref>
== In coroutines == Coroutines are a fine-grained concurrency primitive, which may be required to yield explicitly. They may enable specifying another function to take control. Coroutines that explicitly yield allow cooperative multitasking.
==See also== {{Portal|Computer programming}} * Coroutines * Java (software platform) * Common Language Runtime * Java virtual machine * Actor model
==References== {{Reflist}}
{{Parallel Computing}}
{{DEFAULTSORT:Yield method}} Category:Operating system technology Category:Concurrent computing Category:Threads (computing) Category:Java (software platform) Category:Computing platforms Category:Compiler optimizations Category:Software optimization Category:Method (computer programming)