Click here to Skip to main content
15,889,931 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: File Pin
vivekphlp27-Apr-07 18:52
vivekphlp27-Apr-07 18:52 
QuestionQuestion about Interlocked functions Pin
HOW WHAT27-Apr-07 17:29
HOW WHAT27-Apr-07 17:29 
AnswerRe: Question about Interlocked functions Pin
Arman S.27-Apr-07 22:49
Arman S.27-Apr-07 22:49 
AnswerRe: Question about Interlocked functions Pin
cmk28-Apr-07 13:23
cmk28-Apr-07 13:23 
GeneralRe: Question about Interlocked functions Pin
HOW WHAT28-Apr-07 14:47
HOW WHAT28-Apr-07 14:47 
GeneralRe: Question about Interlocked functions Pin
cmk28-Apr-07 15:20
cmk28-Apr-07 15:20 
GeneralRe: Question about Interlocked functions Pin
HOW WHAT28-Apr-07 22:21
HOW WHAT28-Apr-07 22:21 
GeneralRe: Question about Interlocked functions Pin
cmk29-Apr-07 0:14
cmk29-Apr-07 0:14 
Interlocked* is needed if you want to do 2 or more things with the value.

In your example:
if( 0 == lock )  lock = 1;
else             lock = 0;

You are doing (at least) 2 things:
1. if( 0 == lock )
2. lock = ...;

Imagine 2 threads, Thread1 and Thread2.
Start with lock = 0.
Thread1 checks 1. above: if( 0 == lock ) and returns true
Thread2 then checks 1. above: if( 0 == lock ) and returns true
Thread1 then does 2. above: lock = 1
Thread2 then does 2. above: lock = 1
Problem: both threads think they are locked.

You must use Interlocked* to make it like 1 instruction (i.e. atomic):
InterlockedCompareExchange(&lock, 1, 0)



...cmk

Save the whales - collect the whole set

GeneralRe: Question about Interlocked functions Pin
HOW WHAT29-Apr-07 4:33
HOW WHAT29-Apr-07 4:33 
GeneralRe: Question about Interlocked functions Pin
cmk29-Apr-07 9:13
cmk29-Apr-07 9:13 
GeneralRe: Question about Interlocked functions Pin
HOW WHAT29-Apr-07 20:05
HOW WHAT29-Apr-07 20:05 
GeneralRe: Question about Interlocked functions Pin
HOW WHAT28-Apr-07 22:48
HOW WHAT28-Apr-07 22:48 
GeneralRe: Question about Interlocked functions Pin
cmk29-Apr-07 0:01
cmk29-Apr-07 0:01 
GeneralRe: Question about Interlocked functions Pin
HOW WHAT29-Apr-07 2:49
HOW WHAT29-Apr-07 2:49 
GeneralRe: Question about Interlocked functions Pin
cmk29-Apr-07 9:04
cmk29-Apr-07 9:04 
Questionhow to make very large numbers Pin
g3RC4n27-Apr-07 15:43
g3RC4n27-Apr-07 15:43 
AnswerRe: how to make very large numbers Pin
David Crow27-Apr-07 17:02
David Crow27-Apr-07 17:02 
GeneralRe: how to make very large numbers Pin
Rajesh R Subramanian27-Apr-07 19:31
professionalRajesh R Subramanian27-Apr-07 19:31 
GeneralRe: how to make very large numbers Pin
g3RC4n27-Apr-07 23:11
g3RC4n27-Apr-07 23:11 
GeneralRe: how to make very large numbers Pin
cp987628-Apr-07 0:21
cp987628-Apr-07 0:21 
GeneralRe: how to make very large numbers Pin
g3RC4n28-Apr-07 8:48
g3RC4n28-Apr-07 8:48 
QuestionLog in to website Pin
baloneyman27-Apr-07 15:42
baloneyman27-Apr-07 15:42 
QuestionRe: Log in to website Pin
Rajesh R Subramanian27-Apr-07 19:30
professionalRajesh R Subramanian27-Apr-07 19:30 
AnswerRe: Log in to website Pin
baloneyman27-Apr-07 22:02
baloneyman27-Apr-07 22:02 
Questiondatabase and CListCtrl Pin
hero199527-Apr-07 14:53
hero199527-Apr-07 14:53 

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.