Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : Joe Seigh Date : Thu Aug 04 2005 04:45 pm Sean Kelly wrote: > David Schwartz wrote: > >>"David Hopwood" wrote in message >>news:OLqIe.861$ia4.479@fe1.news.blueyonder.co.uk... >> >> >>>"Applications shall ensure that access to any memory location by more >>> than one thread of control (threads or processes) is restricted such >>> that no thread of control can read or modify a memory location while >>> another thread of control may be modifying it." >> >> That still bites you. > > > Out of curiosity, is this a rule that is always adhered to or do some > folks bend the rules if they're targeting specific hardware? In other > words, if I wrote inline asm on a POSIX system that code contained > memory ordering instructions, how likely is it that the code block > would not behave as intended? Basically, I'm wondering whether/how > anyone does lockless programming on such systems if the spec makes no > guarantees about correct behavior. > > You need to rely on platform (OS, hw, and/or compiler) specific behavior. For gcc, the inline assembler needs the volatile attribute and memory in the clobber list. External calls are almost certainly safe despite the FUD spread by some. It's a pretty stupid claim that the compiler might optimize across an external call when those external routines may contain calls to "memory synchronizing" Posix functions. If anything Posix compliance almost guarantees this behavior has to take place. I'd worry more about non Posix compliant compilers. Even if you stuck strictly to Posix functions, Posix doesn't address things like word tearing, so you couldn't write "correct" portable programs even if you wanted to. Plus there's the fact that Posix has no formal semantics so you couldn't prove a program correct if you wanted to do that either. The arguments that Posix functions could do this or that are a little silly. A posix program could turn itself into a bunny rabbit and be compliant. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .