Click here to Skip to main content
16,004,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
HOW WHAT wrote:
Unclear why those code run not happen error, if
if "volatile bool Sentinel = true;" -> "bool Sentinel = true;" , have some different?


http://msdn2.microsoft.com/en-us/library/12a04hfd(VS.80).aspx[^]

volatile is important.
It tells the compiler that the value could change any time.
e.g.
void  Thread1( void )
{
    while( Sentinal ) {
        ...
    }
}
void  Thread2( void )
{
    ...
    Sentinal = false;
    (wait for Thread1 to finish)
    ...
}

If Sentinal is NOT volatile then Thread1 may cache the value of Sentinal when the Thread1 starts and never reload it becuase it is not used anywhere else in Thread1 (it optimizes the load out). In the example above this could cause Thread2 to wait forever becuase Thread1 never exits.

If Sentinal IS volatile then Thread1 reloads the value in each iteration of the while loop.
Therefore when Thread2 changes Sentinal Thread1 will see the change.


...cmk

Save the whales - collect the whole set

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 
AnswerRe: database and CListCtrl Pin
David Crow27-Apr-07 17:04
David Crow27-Apr-07 17:04 
QuestionPlaySound using Add resource (MFC) Pin
YUANGE27-Apr-07 7:47
YUANGE27-Apr-07 7:47 
AnswerRe: PlaySound using Add resource (MFC) Pin
David Crow27-Apr-07 9:34
David Crow27-Apr-07 9:34 
QuestionLNK errors while using tiff.lib!!! Pin
Kiran Satish27-Apr-07 7:42
Kiran Satish27-Apr-07 7:42 
AnswerRe: LNK errors while using tiff.lib!!! Pin
bob1697227-Apr-07 14:38
bob1697227-Apr-07 14:38 

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.