This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question on semantics


Mike Stump wrote:

On May 4, 2005, at 10:59 AM, Chris Friesen wrote:

If I share memory between two processes, and protect access to the memory using standard locking (fcntl(), for instance), do I need to specify that the memory is volatile?

It is safer to. People might compile your whole app at once for better optimization, and the compiler might be just smart enough to optimize it away.

One problem with using volatile is that it can destroy performance. I only need to really read it in from memory the first time after I take a lock, and flush it out to memory at the time I give up the lock. If I specify it as volatile, I force the compiler to read/write memory on *every* access, even when it's not necessary.


Also, what about threads and pthread locking? Do I need to use volatile there? If not, then what about using pthread locking between processes?

So far I've gotten answers all over the map from people who all claim to know what's going on. It's a pain.

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]