Click here to Skip to main content
15,911,890 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MSDN volatile sample Pin
Maxwell Chen27-Dec-07 23:01
Maxwell Chen27-Dec-07 23:01 
GeneralRe: MSDN volatile sample Pin
George_George27-Dec-07 23:47
George_George27-Dec-07 23:47 
GeneralRe: MSDN volatile sample Pin
Maxwell Chen28-Dec-07 1:48
Maxwell Chen28-Dec-07 1:48 
GeneralRe: MSDN volatile sample Pin
George_George28-Dec-07 2:09
George_George28-Dec-07 2:09 
GeneralRe: MSDN volatile sample Pin
CPallini28-Dec-07 2:22
mveCPallini28-Dec-07 2:22 
GeneralRe: MSDN volatile sample Pin
George_George28-Dec-07 2:31
George_George28-Dec-07 2:31 
GeneralYes. Pin
CPallini28-Dec-07 2:41
mveCPallini28-Dec-07 2:41 
GeneralRe: Yes. Pin
George_George28-Dec-07 2:57
George_George28-Dec-07 2:57 
Thanks CPallini,


Now I strongly suspect whether compiler will generate any wrong code -- functional wrong code. In MSDN sample, variable Sentinel is used to act as a shared variable between thread1 and thread2. Compiler should guarantee that both threads can read/write the correct value of Sentinel.

It seems that volatile will make wrong optimization to prevent thread1 from reading the most recent correct value set by thread2? I think it will bring high risks to careless developers, who does not know about volatile and forget to put it ahead of the variable, which will result in the wrong optimization of compiler.

What is your perspective on such optimization?


regards,
George
GeneralRe: Yes. Pin
CPallini28-Dec-07 3:18
mveCPallini28-Dec-07 3:18 
GeneralRe: Yes. Pin
George_George28-Dec-07 3:26
George_George28-Dec-07 3:26 
GeneralRe: Yes. Pin
CPallini28-Dec-07 3:46
mveCPallini28-Dec-07 3:46 
GeneralRe: Yes. Pin
George_George28-Dec-07 3:53
George_George28-Dec-07 3:53 
GeneralRe: Yes. Pin
CPallini28-Dec-07 4:05
mveCPallini28-Dec-07 4:05 
GeneralRe: Yes. Pin
George_George28-Dec-07 18:18
George_George28-Dec-07 18:18 
GeneralRe: Yes. Pin
CPallini28-Dec-07 22:50
mveCPallini28-Dec-07 22:50 
GeneralRe: Yes. Pin
George_George28-Dec-07 23:08
George_George28-Dec-07 23:08 
GeneralRe: Yes. Pin
CPallini28-Dec-07 23:45
mveCPallini28-Dec-07 23:45 
GeneralRe: Yes. Pin
George_George29-Dec-07 0:00
George_George29-Dec-07 0:00 
GeneralRe: Yes. Pin
Maxwell Chen28-Dec-07 4:25
Maxwell Chen28-Dec-07 4:25 
GeneralRe: Yes. Pin
JudyL_MD28-Dec-07 12:21
JudyL_MD28-Dec-07 12:21 
GeneralRe: Yes. Pin
George_George28-Dec-07 18:17
George_George28-Dec-07 18:17 
GeneralRe: Yes. [modified] Pin
JudyL_MD28-Dec-07 20:01
JudyL_MD28-Dec-07 20:01 
GeneralRe: Yes. Pin
George_George28-Dec-07 23:01
George_George28-Dec-07 23:01 
GeneralRe: Yes. Pin
JudyL_MD29-Dec-07 4:40
JudyL_MD29-Dec-07 4:40 
GeneralRe: Yes. Pin
George_George29-Dec-07 19:39
George_George29-Dec-07 19: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.