Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4FEA082C.9010809@loria.fr> (permalink) |
|---|---|
| Date | 2012-06-26 21:06 +0200 |
| From | Jens Gustedt <jens.gustedt@loria.fr> |
| Newsgroups | comp.lang.c |
| Subject | Re: how to use volatile key word? |
| References | <4fa787bc-0930-4c4e-a1e9-dbf94b909e8a@googlegroups.com> |
| Organization | Guest of ProXad - France |
Am 26.06.2012 18:10, schrieb 伏虎: > how to use volatile key word? > > Assume I have a global variable shared by two or more tasks. Do I > need to declare it as volatile? > > When will a non-volatile global variable be written back to memory > from a register copy? Before a function call? Or before the return > statement? Using it in such a context is not sufficient. Even with volatile there would be no guarantee that the compiler would load a consistent value from memory. E.g in extreme cases it could load the upper half of a variable in one load and and the lower half with another. Your program then could see a mix of two different values. The feature that you would be needing is C11's _Atomic and not volatile. Many compilers already provide similar features as extensions. P99 supports part of the C11 syntax on top of gcc and cousins. Jens
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to use volatile key word? 伏虎 <fuhu314@hotmail.com> - 2012-06-26 09:10 -0700
Re: how to use volatile key word? Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-06-26 18:56 +0200
Re: how to use volatile key word? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-26 12:57 -0400
Re: how to use volatile key word? Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-26 21:06 +0200
Re: how to use volatile key word? David Brown <david@westcontrol.removethisbit.com> - 2012-06-27 09:08 +0200
Re: how to use volatile key word? Tim Wescott <tim@seemywebsite.com> - 2012-06-27 11:10 -0500
Re: how to use volatile key word? Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-27 10:28 -0700
csiph-web