-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLockThis.qhelp
More file actions
30 lines (23 loc) · 816 Bytes
/
LockThis.qhelp
File metadata and controls
30 lines (23 loc) · 816 Bytes
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>It is inadvisable to use <code>this</code> in a <code>lock</code> statement,
because other classes could also attempt to lock the object, resulting in inefficiency or
deadlock.</p>
</overview>
<recommendation>
<p>Create a <code>private readonly Object</code>
which is used exclusively for locking. This ensures that no other classes can
use the same lock.
</p></recommendation>
<example>
<p>The following example uses a <code>private readonly</code>
variable called <code>mutex</code> to use in the <code>lock</code> statement.</p>
<sample src="LockThis.cs" />
</example>
<references>
<li>MSDN, C# Reference: <a href="http://msdn.microsoft.com/en-gb/library/c5kehkcz.aspx">lock Statement</a>.</li>
</references>
</qhelp>