blob: 3b05231cd8894ac33f95dac1c32f8a6987225d8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
.\" Copyright (C) Tom Bjorkholm & Markus Kuhn, 1996
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.\"
.\" 1996-04-01 Tom Bjorkholm <tomb@mydata.se>
.\" First version written
.\" 1996-04-10 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
.\" revision
.\"
.TH sched_yield 2 2023-03-30 "Linux man-pages 6.04"
.SH NAME
sched_yield \- yield the processor
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B #include <sched.h>
.PP
.B int sched_yield(void);
.fi
.SH DESCRIPTION
.BR sched_yield ()
causes the calling thread to relinquish the CPU.
The thread is moved to the end of the queue for its static
priority and a new thread gets to run.
.SH RETURN VALUE
On success,
.BR sched_yield ()
returns 0.
On error, \-1 is returned, and
.I errno
is set to indicate the error.
.SH ERRORS
In the Linux implementation,
.BR sched_yield ()
always succeeds.
.SH STANDARDS
POSIX.1-2008.
.SH HISTORY
POSIX.1-2001.
.SH NOTES
If the calling thread is the only thread in the highest
priority list at that time,
it will continue to run after a call to
.BR sched_yield ().
.PP
POSIX systems on which
.BR sched_yield ()
is available define
.B _POSIX_PRIORITY_SCHEDULING
in
.IR <unistd.h> .
.PP
Strategic calls to
.BR sched_yield ()
can improve performance by giving other threads or processes
a chance to run when (heavily) contended resources (e.g., mutexes)
have been released by the caller.
Avoid calling
.BR sched_yield ()
unnecessarily or inappropriately
(e.g., when resources needed by other
schedulable threads are still held by the caller),
since doing so will result in unnecessary context switches,
which will degrade system performance.
.PP
.BR sched_yield ()
is intended for use with real-time scheduling policies (i.e.,
.B SCHED_FIFO
or
.BR SCHED_RR ).
Use of
.BR sched_yield ()
with nondeterministic scheduling policies such as
.B SCHED_OTHER
is unspecified and very likely means your application design is broken.
.SH SEE ALSO
.BR sched (7)
|