Click here to Skip to main content
16,017,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: DLL and EXE files Pin
Matthew Faithfull3-Jun-07 1:18
Matthew Faithfull3-Jun-07 1:18 
AnswerRe: DLL and EXE files Pin
prithaa3-Jun-07 1:42
prithaa3-Jun-07 1:42 
GeneralRe: DLL and EXE files Pin
Matthew Faithfull3-Jun-07 2:59
Matthew Faithfull3-Jun-07 2:59 
AnswerRe: DLL and EXE files Pin
Hamid_RT3-Jun-07 7:33
Hamid_RT3-Jun-07 7:33 
QuestionHow do I make a child dialog draw on a different HDC Pin
KellyR2-Jun-07 17:51
KellyR2-Jun-07 17:51 
AnswerRe: How do I make a child dialog draw on a different HDC Pin
Naveen3-Jun-07 16:17
Naveen3-Jun-07 16:17 
Questionagain for InterlockedIncrement() Pin
includeh102-Jun-07 16:52
includeh102-Jun-07 16:52 
AnswerRe: again for InterlockedIncrement() Pin
Matthew Faithfull3-Jun-07 1:07
Matthew Faithfull3-Jun-07 1:07 
iy = InterlockedIncrement(&iv); is essentially the same thing as

<br />
SomeCriticalSection.Lock();<br />
iy = (++iv);<br />
SomeCriticalSection.Unlock();<br />


The reason you would use InterlockedIncrement is if iv is being accessed by more than one thread, as you know, and you want to increment and get the value of iv with no possibility of another thread steping in and changing it in the mean time. Consider one possible break down of the unprotected code

iy = iv++;

in 'optimised' pseudo assembler Big Grin | :-D

1 load iv into a register
2 If iv is an even number
3 set bit 1 on the register
4 else
5 do a full ADD operation on 1 and iv
6 store the register contents back again into the memory of iv
//..one critical weak point is here
7 load iv from memory again
8 store it a second time into the memory of iy

In theory at least another thread could jump in at the critical weak point in the lines above, and do any amount of stuff with iv in memory D'Oh! | :doh: Total disaster can then ensue. In practice this is unlikely because a decent compiler backend will optimise out the storing and reloading of iv before assignment to iy. It will just store the same value twice.
The reason you would still use the InterlockedIncrement is not to protect this thread but to protect the other thread which while we are stopped on step 5 writes iv (does it's own step 6) and then finds that it hasn't been written because we jump back in and write over it in our step 6. The iv and iy in the other thread will then be out of sync. Smile | :)

I have found very few situations where InterlockedIncrement is really needed but there are a few.


Nothing is exactly what it seems but everything with seems can be unpicked.

GeneralRe: again for InterlockedIncrement() Pin
Mark Salsbery4-Jun-07 5:40
Mark Salsbery4-Jun-07 5:40 
AnswerRe: again for InterlockedIncrement() Pin
Mark Salsbery4-Jun-07 5:45
Mark Salsbery4-Jun-07 5:45 
QuestionSuggestion: Subject Matter Editors Pin
Jeffrey Walton2-Jun-07 11:46
Jeffrey Walton2-Jun-07 11:46 
AnswerRe: Suggestion: Subject Matter Editors Pin
Hans Dietrich3-Jun-07 0:14
mentorHans Dietrich3-Jun-07 0:14 
GeneralRe: Suggestion: Subject Matter Editors Pin
Matthew Faithfull3-Jun-07 1:12
Matthew Faithfull3-Jun-07 1:12 
GeneralRe: Suggestion: Subject Matter Editors Pin
Cliff Hatch3-Jun-07 2:32
Cliff Hatch3-Jun-07 2:32 
GeneralRe: Suggestion: Subject Matter Editors Pin
Hans Dietrich3-Jun-07 4:14
mentorHans Dietrich3-Jun-07 4:14 
GeneralRe: Suggestion: Subject Matter Editors Pin
Jeffrey Walton3-Jun-07 9:35
Jeffrey Walton3-Jun-07 9:35 
GeneralRe: Suggestion: Subject Matter Editors Pin
Jeffrey Walton3-Jun-07 9:33
Jeffrey Walton3-Jun-07 9:33 
AnswerRe: Suggestion: Subject Matter Editors Pin
Gary R. Wheeler3-Jun-07 1:52
Gary R. Wheeler3-Jun-07 1:52 
GeneralRe: Suggestion: Subject Matter Editors Pin
Jeffrey Walton3-Jun-07 9:28
Jeffrey Walton3-Jun-07 9:28 
QuestionNTFS Alternate Data Streams Pin
Akin Ocal2-Jun-07 10:26
Akin Ocal2-Jun-07 10:26 
AnswerRe: NTFS Alternate Data Streams Pin
Mark Salsbery2-Jun-07 15:17
Mark Salsbery2-Jun-07 15:17 
Questionlog10 ( 3/2 ) = 0.000 Help me! :( [modified] Solved Pin
Immunity182-Jun-07 8:14
Immunity182-Jun-07 8:14 
AnswerRe: log10 ( 3/2 ) = 0.000 Help me! :( [modified] Solved Pin
Christian Graus2-Jun-07 21:55
protectorChristian Graus2-Jun-07 21:55 
Questionmanaged/unmanaged code Pin
includeh102-Jun-07 6:09
includeh102-Jun-07 6:09 
AnswerRe: managed/unmanaged code Pin
Sathesh Sakthivel2-Jun-07 7:39
Sathesh Sakthivel2-Jun-07 7:39 

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.