On Wed, Aug 21, 2002 at 09:41:03AM +0200, Martin Maletinsky wrote: > Hello, > > What are the rules for the use of the 'volatile' qualifier in the Linux kernel source? http://www.embedded.com/story/OEG20010615S0107, which gives a good explanation of the > volatile' qualifier, states that global variables modified by an interrupt service routine and global variables within a multi-threaded application should be declared > volatile. > However, looking e.g. at the task_struct in the 2.4.7 sources, I noticed that only the state and the need_reschedule fields are declared volatile, although I imagine, that > there must be other fields as well (e.g. the pointers linking the task_struct into the various task lists, or the signal related information), which may be modified by > multiple threads and/or service routines - why aren't those (e.g. the run_list or the link_count fields) declared volatile? AFAIK volatile is mostly useless, because it does not guarantee much. It just guarantees, that compiler will never keep the value anywhere but the given memory location (that is it won't be kept in registers). That is useful for flags used in schedule, since they are not parameters and so gcc wouldn't care to store them in memory (from registers). But for the rest more guarantees are needed. For these either barrier()s (they force GCC not to keep values in registers, but in addition synchronize CPU caches on SMP), or atomic operations or locks. These all force required properties and volatile keyword does not matter here. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/