summaryrefslogtreecommitdiff
path: root/content/xdocs/NeverUseStaticLocalVariables.html
diff options
context:
space:
mode:
Diffstat (limited to 'content/xdocs/NeverUseStaticLocalVariables.html')
-rwxr-xr-xcontent/xdocs/NeverUseStaticLocalVariables.html48
1 files changed, 0 insertions, 48 deletions
diff --git a/content/xdocs/NeverUseStaticLocalVariables.html b/content/xdocs/NeverUseStaticLocalVariables.html
deleted file mode 100755
index 1a3b73b9fd..0000000000
--- a/content/xdocs/NeverUseStaticLocalVariables.html
+++ /dev/null
@@ -1,48 +0,0 @@
-<html>
- <head>
- <title>Apache Qpid : NeverUseStaticLocalVariables</title>
- <link rel="stylesheet" href="styles/site.css" type="text/css" />
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
-
- <body>
- <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
- <tr>
- <td valign="top" class="pagebody">
- <div class="pageheader">
- <span class="pagetitle">
- Apache Qpid : NeverUseStaticLocalVariables
- </span>
- </div>
- <div class="pagesubheading">
- This page last changed on Oct 19, 2006 by <font color="#0050B2">mmccorma</font>.
- </div>
-
- <p>Never do this:</p>
-<div class="code"><div class="codeContent">
-<pre class="code-java">void f() {
- <span class="code-keyword">static</span> <span class="code-object">int</span> x = 10;
-}</pre>
-</div></div>
-
-<p>Static on a local variable means the compiler is supposed initialize it the first time the function is entered, but it holds its value on subsequent calls. It's sometimes used for local counters, or in the "Myers Singleton" approach to singletons. </p>
-
-<p>The problem is that the C++ standard does not require compilers to make this initialization thread safe, and almost none do. So in a multi threaded program if there are concurrent first calls to f there will be a disaster. Using this for singletons is particularly prone to multi-threaded collisions.</p>
-
-<p>So use the less elegant but safer options: make the variable a class member for member functions or a file-private global for non-member functions.</p>
-
-
-
- </td>
- </tr>
- </table>
- <table border="0" cellpadding="0" cellspacing="0" width="100%">
- <tr>
- <td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
- </tr>
- <tr>
- <td align="center"><font color="grey">Document generated by Confluence on Apr 22, 2008 02:47</font></td>
- </tr>
- </table>
- </body>
-</html> \ No newline at end of file