SunQuest
 
       C++
  Home arrow C++ arrow Page 5 - C++ in Theory: Why the Double Check Lock P...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

C++ in Theory: Why the Double Check Lock Pattern Isn`t 100% Thread Safe
By: J. Nakamura
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2005-08-01

    Table of Contents:
  • C++ in Theory: Why the Double Check Lock Pattern Isn`t 100% Thread Safe
  • The Original Problem
  • The Double Checked Locking Pattern
  • Object Creation
  • Multiprocessor Machines
  • Portable Solutions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    C++ in Theory: Why the Double Check Lock Pattern Isn`t 100% Thread Safe - Multiprocessor Machines


    (Page 5 of 6 )

    So should we worry about multithreading? There is a switch for the compiler that forces it to generate single threaded code: we’ll get out of jail free, pass go and collect 200 bucks, right?

    Maybe you are safe for now, but if you have followed the chip designs of Intel lately (and heard about that massive parallel CELL chip that is going to power the Playstation 3), by the end of 2005 it will be perfectly normal for home PCs to have a Dual Core CPU (a CPU effectively containing two physical processors), where both cores are hyperthreaded as well. A hyperthread is a nifty way of maximizing instruction ordering on the CPU by filling up time that would normally remain unused. This makes it act like two logical processors while you are physically only running one. Thus PCs will appear to have four logical processors on board! (For dual processor machines the number of logical processors ramps up to eight!)

    Still, if you are writing and compiling single threaded code, your application will only be able to run at 25 percent of its maximum speed. Why? Because the Task Manager will only show that the processor is running at 100% when all four hyperthreads are being maxed out.

    It's a sneaky way to try and maintain Moore’s Law, but people will think your code is just plain slow! Concurrent programming is going to be an issue, and maybe sooner than you thought.

    More C++ Articles
    More By J. Nakamura


       · well, why not add an intermediate step to make sure that pInstance is only != 0 when...
       · What about this:if(!initialized){ lock(); if(instance == 0){ instance =...
       · your didn't read the article carefully.p3:Trying to force the compiler to a...
       · if the first thread set the initialized = true first, the second thread will assume...
     

    C++ ARTICLES

    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection
    - Temporary Variables: Chasing Temporaries Away







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway