HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 456089 thumbnail
User 225256 avatar

By mswatcher
via codeproject.com
Published: Jul 30 2010 / 02:35

Everything there is to know about Singletons and thread safety.
  • 9
  • 1
  • 1787
  • 0

Comments

Add your comment
User 447031 avatar

iirekm replied ago:

1 votes Vote down Vote up Reply

One thing you probably forgot: add 'volatile' keyword to the variable that holds singleton. Otherwise some compilers could cache the value in a CPU registry and you may get unpredictable results.
The same 'double-checking' pattern works also in Java (since 1.5).

The problem with singleton is that if you have lots of singleton objects, this leads to lots of ugly boilerplate code. Better use a dependency injection framework, like Spring in Java.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.