namespaces.7: ffix
[man-pages.git] / man2 / sched_yield.2
blob2a335d53c6446f57ceb4c487fa86099fc4def74f
1 .\" Copyright (C) Tom Bjorkholm & Markus Kuhn, 1996
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\" 1996-04-01 Tom Bjorkholm <tomb@mydata.se>
25 .\"            First version written
26 .\" 1996-04-10 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
27 .\"            revision
28 .\"
29 .TH SCHED_YIELD 2 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 sched_yield \- yield the processor
32 .SH SYNOPSIS
33 .nf
34 .B #include <sched.h>
35 .PP
36 .B int sched_yield(void);
37 .fi
38 .SH DESCRIPTION
39 .BR sched_yield ()
40 causes the calling thread to relinquish the CPU.
41 The thread is moved to the end of the queue for its static
42 priority and a new thread gets to run.
43 .SH RETURN VALUE
44 On success,
45 .BR sched_yield ()
46 returns 0.
47 On error, \-1 is returned, and
48 .I errno
49 is set to indicate the error.
50 .SH ERRORS
51 In the Linux implementation,
52 .BR sched_yield ()
53 always succeeds.
54 .SH CONFORMING TO
55 POSIX.1-2001, POSIX.1-2008.
56 .SH NOTES
57 If the calling thread is the only thread in the highest
58 priority list at that time,
59 it will continue to run after a call to
60 .BR sched_yield ().
61 .PP
62 POSIX systems on which
63 .BR sched_yield ()
64 is available define
65 .B _POSIX_PRIORITY_SCHEDULING
67 .IR <unistd.h> .
68 .PP
69 Strategic calls to
70 .BR sched_yield ()
71 can improve performance by giving other threads or processes
72 a chance to run when (heavily) contended resources (e.g., mutexes)
73 have been released by the caller.
74 Avoid calling
75 .BR sched_yield ()
76 unnecessarily or inappropriately
77 (e.g., when resources needed by other
78 schedulable threads are still held by the caller),
79 since doing so will result in unnecessary context switches,
80 which will degrade system performance.
81 .PP
82 .BR sched_yield ()
83 is intended for use with real-time scheduling policies (i.e.,
84 .BR SCHED_FIFO
86 .BR SCHED_RR ).
87 Use of
88 .BR sched_yield ()
89 with nondeterministic scheduling policies such as
90 .BR SCHED_OTHER
91 is unspecified and very likely means your application design is broken.
92 .SH SEE ALSO
93 .BR sched (7)