1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../../css/manpage.css" type="text/css" /> 7 <style type="text/css"><!-- 8 span.static_style 9 { 10 font-size : 8pt; 11 color : white; 12 font-weight : bold; 13 background : #44f; 14 border-left : solid 1px #aaf; 15 border-top : solid 1px #aaf; 16 border-right : solid 1px #00c; 17 border-bottom : solid 1px #00c; 18 padding-left : 2px; 19 padding-right : 2px; 20 } 21 22 span.virtual_style 23 { 24 font-size : 8pt; 25 color : white; 26 font-weight : bold; 27 background : #0a0; 28 border-left : solid 1px #0f0; 29 border-top : solid 1px #0f0; 30 border-right : solid 1px #060; 31 border-bottom : solid 1px #060; 32 padding-left : 2px; 33 padding-right : 2px; 34 } 35 36 span.protected_style 37 { 38 font-size : 8pt; 39 color : white; 40 font-weight : bold; 41 background : #444; 42 border-left : solid 1px #ccc; 43 border-top : solid 1px #ccc; 44 border-right : solid 1px #222; 45 border-bottom : solid 1px #222; 46 padding-left : 2px; 47 padding-right : 2px; 48 } 49 --></style> 50<title>nn::os::CriticalSection</title> 51 </head> 52 <body> 53<h1><CODE>nn::os::CriticalSection</CODE> Class</h1> 54 <div class="section"> 55<b>Header file: </b>nn/os.h</div> 56<h2>Syntax</h2> 57 <div class="section"> 58 <pre class="definition">class CriticalSection : private ADLFireWall::NonCopyable<CriticalSection></pre> 59 </div> 60<h2>Description</h2> 61 <div class="section"> 62<p>Class for handling critical sections. Critical sections are synchronization objects used for providing mutual exclusion.</p><p>This mechanism prevents certain areas within programs from being run simultaneously within multiple threads, and also prevents resources from being accessed by multiple threads simultaneously.</p><p>Critical sections play the same role as mutexes (<a href="../../../nn/os/Mutex/Overview.html"><CODE>nn::os::Mutex</CODE></a>), but they have the following limitations.</p><p><itemizedlist><listitem><para>They can be used only to provide mutual exclusion within a single application. </para></listitem><listitem><para>No priority inheritance takes place. Problems such as priority inversion may occur.</para></listitem><listitem><para>Critical sections use more memory to store objects than mutexes do.</para></listitem></itemizedlist> 63The <a href="../../../nn/os/CriticalSection/Overview.html"><CODE>nn::os::CriticalSection</CODE></a> class performs considerably faster than <a href="../../../nn/os/Mutex/Overview.html"><CODE>nn::os::Mutex</CODE></a> when there are no lock collisions between threads. In most cases, use <a href="../../../nn/os/CriticalSection/Overview.html"><CODE>nn::os::CriticalSection</CODE></a> instead of <a href="../../../nn/os/Mutex/Overview.html"><CODE>nn::os::Mutex</CODE></a>.</p><p>The use of <a href="../../../nn/os/CriticalSection/ScopedLock/Overview.html"><CODE>nn::os::CriticalSection::ScopedLock</CODE></a> makes it possible to enter a critical section when an object is created and stay in the critical section until the scope is exited.</p><!-- write here --></div> 64 <a name="class" id="class"> 65<h2>Classes</h2> 66 <div class="section"> 67 <table class="members"> 68 <tr> 69 <th> 70<a href="../../../nn/os/CriticalSection/ScopedLock/Overview.html"><CODE>nn::os::CriticalSection::ScopedLock</CODE></a> 71 </th> 72<td>Enters a critical section when an object is created and stays in until the scope is exited.</td> 73 </tr> 74 </table> 75 </div> 76 </a> <a name="function" id="function"> 77<h2>Member Functions</h2> 78 <div class="section"> 79 <table class="members"> 80 <tr> 81 <td width="100"> </td> 82 <th> 83<a href="../../../nn/os/CriticalSection/CriticalSection.html"><CODE>CriticalSection</CODE></a> 84 </th> 85<td>Constructs an object.</td> 86 </tr> 87 <tr> 88 <td width="100"> </td> 89 <th> 90<a href="../../../nn/os/CriticalSection/Initialize.html"><CODE>Initialize</CODE></a> 91 </th> 92<td>Initializes an object.</td> 93 </tr> 94 <tr> 95 <td width="100"> </td> 96 <th> 97<a href="../../../nn/os/CriticalSection/TryInitialize.html"><CODE>TryInitialize</CODE></a> 98 </th> 99<td>Tries to initialize an object.</td> 100 </tr> 101 <tr> 102 <td width="100"> </td> 103 <th> 104<a href="../../../nn/os/CriticalSection/Finalize.html"><CODE>Finalize</CODE></a> 105 </th> 106<td>Destroys a critical section.</td> 107 </tr> 108 <tr> 109 <td width="100"> </td> 110 <th> 111<a href="../../../nn/os/CriticalSection/~CriticalSection.html"><CODE>~CriticalSection</CODE></a> 112 </th> 113<td>Destructor.</td> 114 </tr> 115 <tr> 116 <td width="100"> </td> 117 <th> 118<a href="../../../nn/os/CriticalSection/Enter.html"><CODE>Enter</CODE></a> 119 </th> 120<td>Locks out other threads and prevents them from entering a critical section. This function blocks.</td> 121 </tr> 122 <tr> 123 <td width="100"> </td> 124 <th> 125<a href="../../../nn/os/CriticalSection/TryEnter.html"><CODE>TryEnter</CODE></a> 126 </th> 127<td>Locks out other threads and prevents them from entering a critical section. This function does not block.</td> 128 </tr> 129 <tr> 130 <td width="100"> </td> 131 <th> 132<a href="../../../nn/os/CriticalSection/Leave.html"><CODE>Leave</CODE></a> 133 </th> 134<td>Unlocks and allows other threads to enter a critical section.</td> 135 </tr> </table> 136 </div> 137 </a> 138<h2>Class Hierarchy</h2> 139 <div class="section"> 140<p class="hierarchy"><span>ADLFireWall::NonCopyable</span><br /> <b>nn::os::CriticalSection</b> 141 </p> 142 </div> 143<h2>Revision History</h2> 144 <div class="section"> 145 <dl class="history"> 146 <dt>2010/01/07</dt> 147<dd>Initial version.<br /> 148 </dd> 149 </dl> 150 </div> 151 <hr><p>CONFIDENTIAL</p></body> 152</html>