Click here to Skip to main content
16,006,762 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: "<<" Operator.. Pin
CPallini30-Dec-07 8:09
mveCPallini30-Dec-07 8:09 
QuestionGame loop Pin
snir_ya30-Dec-07 4:03
snir_ya30-Dec-07 4:03 
GeneralRe: Game loop Pin
Jeremy Falcon30-Dec-07 14:48
professionalJeremy Falcon30-Dec-07 14:48 
GeneralRe: Game loop Pin
Mark Salsbery30-Dec-07 14:50
Mark Salsbery30-Dec-07 14:50 
GeneralRe: Game loop Pin
Jeremy Falcon30-Dec-07 14:55
professionalJeremy Falcon30-Dec-07 14:55 
GeneralRe: Game loop Pin
Mark Salsbery30-Dec-07 15:07
Mark Salsbery30-Dec-07 15:07 
GeneralRe: Game loop Pin
snir_ya31-Dec-07 0:19
snir_ya31-Dec-07 0:19 
GeneralDouble-Checked Locking pattern issue Pin
George_George30-Dec-07 3:26
George_George30-Dec-07 3:26 
Hello gurus,


For the wellknown Double-Checked Locking pattern,

http://www.ddj.com/184405726?pgno=1

Step 1: Allocate memory to hold a Singleton object.
Step 2: Construct a Singleton object in the allocated memory.
Step 3: Make pInstance point to the allocated memory.

After reading for a couple of times, I still do not understand why some compiler will exchange step 2 and step 3 code? If there are any exception in step 2, the swap code will make pInstance point to an invalid memory address. Any ideas why compiler do the swap?

Singleton* Singleton::instance() {
    if (pInstance == 0) {
    Lock lock;
        if (pInstance == 0) {
        pInstance = // Step 3
        operator new(sizeof(Singleton)); // Step 1
        new (pInstance) Singleton; // Step 2
        }
    }
    return pInstance;
}



thanks in advance,
George
GeneralRe: Double-Checked Locking pattern issue Pin
CPallini30-Dec-07 3:41
mveCPallini30-Dec-07 3:41 
GeneralRe: Double-Checked Locking pattern issue Pin
George_George30-Dec-07 3:56
George_George30-Dec-07 3:56 
GeneralRe: Double-Checked Locking pattern issue Pin
CPallini30-Dec-07 4:09
mveCPallini30-Dec-07 4:09 
GeneralRe: Double-Checked Locking pattern issue Pin
George_George31-Dec-07 3:32
George_George31-Dec-07 3:32 
GeneralRe: Double-Checked Locking pattern issue Pin
CPallini31-Dec-07 3:51
mveCPallini31-Dec-07 3:51 
GeneralRe: Double-Checked Locking pattern issue Pin
George_George31-Dec-07 4:30
George_George31-Dec-07 4:30 
GeneralRe: Double-Checked Locking pattern issue Pin
CPallini31-Dec-07 6:01
mveCPallini31-Dec-07 6:01 
GeneralRe: Double-Checked Locking pattern issue Pin
George_George31-Dec-07 6:25
George_George31-Dec-07 6:25 
GeneralSure. Pin
CPallini31-Dec-07 6:28
mveCPallini31-Dec-07 6:28 
QuestionDrawing textures using sprites (DirectX) Pin
Hanan88830-Dec-07 2:39
Hanan88830-Dec-07 2:39 
GeneralRe: Drawing textures using sprites (DirectX) Pin
Jeremy Falcon30-Dec-07 14:43
professionalJeremy Falcon30-Dec-07 14:43 
GeneralRe: Drawing textures using sprites (DirectX) Pin
Hanan88830-Dec-07 21:55
Hanan88830-Dec-07 21:55 
Questionhow to create a self contained dialog that can be used in mutiple applications? Pin
@largeinsd29-Dec-07 20:00
@largeinsd29-Dec-07 20:00 
AnswerRe: how to create a self contained dialog that can be used in mutiple applications? Pin
David Crow30-Dec-07 3:14
David Crow30-Dec-07 3:14 
AnswerRe: how to create a self contained dialog that can be used in mutiple applications? Pin
Bram van Kampen30-Dec-07 4:11
Bram van Kampen30-Dec-07 4:11 
AnswerRe: how to create a self contained dialog that can be used in mutiple applications? Pin
Mark Salsbery30-Dec-07 10:32
Mark Salsbery30-Dec-07 10:32 
Questioneh, what does "owner drawn" mean? Pin
@largeinsd29-Dec-07 16:49
@largeinsd29-Dec-07 16:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.