sfmlinstaller

sfmlinstaller Mercurial Source Tree


Root/windows/doc/html/classsf_1_1Mutex.htm

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
        <!--<link rel='stylesheet' type='text/css' href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
        <link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
    </head>
    <body>
        <div id="banner-container">
            <div id="banner">
                <span id="sfml">SFML</span>
            </div>
        </div>
        <div id="content">
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.htm"><span>Main Page</span></a></li>
      <li><a href="modules.htm"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.htm"><span>Classes</span></a></li>
      <li><a href="files.htm"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.htm"><span>Class List</span></a></li>
      <li><a href="classes.htm"><span>Class Index</span></a></li>
      <li><a href="hierarchy.htm"><span>Class Hierarchy</span></a></li>
      <li><a href="functions.htm"><span>Class Members</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1Mutex.htm">Mutex</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> |
<a href="classsf_1_1Mutex-members.htm">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">sf::Mutex Class Reference<div class="ingroups"><a class="el" href="group__system.htm">System module</a></div></div>  </div>
</div><!--header-->
<div class="contents">
 
<p>Blocks concurrent access to shared resources from multiple threads. 
 <a href="classsf_1_1Mutex.htm#details">More...</a></p>
 
<p><code>#include <<a class="el" href="Mutex_8hpp_source.htm">Mutex.hpp</a>></code></p>
<div class="dynheader">
Inheritance diagram for sf::Mutex:</div>
<div class="dyncontent">
 <div class="center">
  <img src="classsf_1_1Mutex.png" usemap="#sf::Mutex_map" alt=""/>
  <map id="sf::Mutex_map" name="sf::Mutex_map">
<area href="classsf_1_1NonCopyable.htm" title="Utility class that makes any derived class non-copyable." alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
</map>
 </div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a9bd52a48320fd7b6db8a78037aad276e"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Mutex.htm#a9bd52a48320fd7b6db8a78037aad276e">Mutex</a> ()</td></tr>
<tr class="memdesc:a9bd52a48320fd7b6db8a78037aad276e"><td class="mdescLeft"> </td><td class="mdescRight">Default constructor.  <a href="#a9bd52a48320fd7b6db8a78037aad276e"></a><br/></td></tr>
<tr class="separator:a9bd52a48320fd7b6db8a78037aad276e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9f76a67b7b6d3918131a692179b4e3f2"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Mutex.htm#a9f76a67b7b6d3918131a692179b4e3f2">~Mutex</a> ()</td></tr>
<tr class="memdesc:a9f76a67b7b6d3918131a692179b4e3f2"><td class="mdescLeft"> </td><td class="mdescRight">Destructor.  <a href="#a9f76a67b7b6d3918131a692179b4e3f2"></a><br/></td></tr>
<tr class="separator:a9f76a67b7b6d3918131a692179b4e3f2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a1a16956a6bbea764480c1b80f2e45763"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763">lock</a> ()</td></tr>
<tr class="memdesc:a1a16956a6bbea764480c1b80f2e45763"><td class="mdescLeft"> </td><td class="mdescRight"><a class="el" href="classsf_1_1Lock.htm" title="Automatic wrapper for locking and unlocking mutexes.">Lock</a> the mutex.  <a href="#a1a16956a6bbea764480c1b80f2e45763"></a><br/></td></tr>
<tr class="separator:a1a16956a6bbea764480c1b80f2e45763"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ade71268ffc5e80756652058b01c23c33"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Mutex.htm#ade71268ffc5e80756652058b01c23c33">unlock</a> ()</td></tr>
<tr class="memdesc:ade71268ffc5e80756652058b01c23c33"><td class="mdescLeft"> </td><td class="mdescRight">Unlock the mutex.  <a href="#ade71268ffc5e80756652058b01c23c33"></a><br/></td></tr>
<tr class="separator:ade71268ffc5e80756652058b01c23c33"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Blocks concurrent access to shared resources from multiple threads. </p>
<p><a class="el" href="classsf_1_1Mutex.htm" title="Blocks concurrent access to shared resources from multiple threads.">Mutex</a> stands for "MUTual EXclusion".</p>
<p>A mutex is a synchronization object, used when multiple threads are involved.</p>
<p>When you want to protect a part of the code from being accessed simultaneously by multiple threads, you typically use a mutex. When a thread is locked by a mutex, any other thread trying to lock it will be blocked until the mutex is released by the thread that locked it. This way, you can allow only one thread at a time to access a critical region of your code.</p>
<p>Usage example: </p>
<div class="fragment"><div class="line">Database database; <span class="comment">// this is a critical resource that needs some protection</span></div>
<div class="line"><a class="code" href="classsf_1_1Mutex.htm" title="Blocks concurrent access to shared resources from multiple threads.">sf::Mutex</a> mutex;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> thread1()</div>
<div class="line">{</div>
<div class="line">    mutex.<a class="code" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763" title="Lock the mutex.">lock</a>(); <span class="comment">// this call will block the thread if the mutex is already locked by thread2</span></div>
<div class="line">    database.write(...);</div>
<div class="line">    mutex.<a class="code" href="classsf_1_1Mutex.htm#ade71268ffc5e80756652058b01c23c33" title="Unlock the mutex.">unlock</a>(); <span class="comment">// if thread2 was waiting, it will now be unblocked</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> thread2()</div>
<div class="line">{</div>
<div class="line">    mutex.<a class="code" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763" title="Lock the mutex.">lock</a>(); <span class="comment">// this call will block the thread if the mutex is already locked by thread1</span></div>
<div class="line">    database.write(...);</div>
<div class="line">    mutex.<a class="code" href="classsf_1_1Mutex.htm#ade71268ffc5e80756652058b01c23c33" title="Unlock the mutex.">unlock</a>(); <span class="comment">// if thread1 was waiting, it will now be unblocked</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>Be very careful with mutexes. A bad usage can lead to bad problems, like deadlocks (two threads are waiting for each other and the application is globally stuck).</p>
<p>To make the usage of mutexes more robust, particularly in environments where exceptions can be thrown, you should use the helper class <a class="el" href="classsf_1_1Lock.htm" title="Automatic wrapper for locking and unlocking mutexes.">sf::Lock</a> to lock/unlock mutexes.</p>
<p>SFML mutexes are recursive, which means that you can lock a mutex multiple times in the same thread without creating a deadlock. In this case, the first call to <a class="el" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763" title="Lock the mutex.">lock()</a> behaves as usual, and the following ones have no effect. However, you must call <a class="el" href="classsf_1_1Mutex.htm#ade71268ffc5e80756652058b01c23c33" title="Unlock the mutex.">unlock()</a> exactly as many times as you called <a class="el" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763" title="Lock the mutex.">lock()</a>. If you don't, the mutex won't be released.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classsf_1_1Lock.htm" title="Automatic wrapper for locking and unlocking mutexes.">sf::Lock</a> </dd></dl>
 
<p>Definition at line <a class="el" href="Mutex_8hpp_source.htm#l00047">47</a> of file <a class="el" href="Mutex_8hpp_source.htm">Mutex.hpp</a>.</p>
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="a9bd52a48320fd7b6db8a78037aad276e"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">sf::Mutex::Mutex </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
 
<p>Default constructor. </p>
 
</div>
</div>
<a class="anchor" id="a9f76a67b7b6d3918131a692179b4e3f2"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">sf::Mutex::~Mutex </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
 
<p>Destructor. </p>
 
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a1a16956a6bbea764480c1b80f2e45763"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Mutex::lock </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
 
<p><a class="el" href="classsf_1_1Lock.htm" title="Automatic wrapper for locking and unlocking mutexes.">Lock</a> the mutex. </p>
<p>If the mutex is already locked in another thread, this call will block the execution until the mutex is released.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classsf_1_1Mutex.htm#ade71268ffc5e80756652058b01c23c33" title="Unlock the mutex.">unlock</a> </dd></dl>
 
</div>
</div>
<a class="anchor" id="ade71268ffc5e80756652058b01c23c33"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Mutex::unlock </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
 
<p>Unlock the mutex. </p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classsf_1_1Mutex.htm#a1a16956a6bbea764480c1b80f2e45763" title="Lock the mutex.">lock</a> </dd></dl>
 
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="Mutex_8hpp_source.htm">Mutex.hpp</a></li>
</ul>
</div><!-- contents -->
        </div>
        <div id="footer-container">
            <div id="footer">
                Copyright � Laurent Gomila  :: 
                Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a>  :: 
            </div>
        </div>
    <script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
 
  ga('create', 'UA-41898676-1', 'srchub.org');
  ga('send', 'pageview');
Page rendered in 0.78314s using 11 queries.
Source at commit tip created 11 years 11 months ago.
By Nathan Adams, Initial commit

Archive Download this file

Branches

Tags

Page rendered in 0.78314s using 11 queries.