]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/critical_enter.9
disk(9): Fix a few mandoc related errors
[FreeBSD/FreeBSD.git] / share / man / man9 / critical_enter.9
1 .\" Copyright (c) 2001,2002 John H. Baldwin <jhb@FreeBSD.org>
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 .\" SUCH DAMAGE.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd October 5, 2005
27 .Dt CRITICAL_ENTER 9
28 .Os
29 .Sh NAME
30 .Nm critical_enter ,
31 .Nm critical_exit
32 .Nd enter and exit a critical region
33 .Sh SYNOPSIS
34 .In sys/param.h
35 .In sys/systm.h
36 .Ft void
37 .Fn critical_enter "void"
38 .Ft void
39 .Fn critical_exit "void"
40 .Sh DESCRIPTION
41 These functions are used to prevent preemption in a critical region of code.
42 All that is guaranteed is that the thread currently executing on a CPU will
43 not be preempted.
44 Specifically, a thread in a critical region will not migrate to another
45 CPU while it is in a critical region.
46 The current CPU may still trigger faults and exceptions during a critical
47 section; however, these faults are usually fatal.
48 .Pp
49 The
50 .Fn critical_enter
51 and
52 .Fn critical_exit
53 functions manage a per-thread counter to handle nested critical sections.
54 If a thread is made runnable that would normally preempt the current thread
55 while the current thread is in a critical section,
56 then the preemption will be deferred until the current thread exits the
57 outermost critical section.
58 .Pp
59 Note that these functions are not required to provide any inter-CPU
60 synchronization, data protection, or memory ordering guarantees and thus
61 should
62 .Em not
63 be used to protect shared data structures.
64 .Pp
65 These functions should be used with care as an infinite loop within a
66 critical region will deadlock the CPU.
67 Also, they should not be interlocked with operations on mutexes, sx locks,
68 semaphores, or other synchronization primitives.
69 One exception to this is that spin mutexes include a critical section,
70 so in certain cases critical sections may be interlocked with spin mutexes.
71 .Sh HISTORY
72 These functions were introduced in
73 .Fx 5.0 .