9e8 Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : Giancarlo Niccolai Date : Thu May 26 2005 12:01 pm David Schwartz wrote: > > "Giancarlo Niccolai" wrote in message > news:d72qan$qoj$1@newsread.albacom.net... > >> They may not appear on another CPU, but I doubt any SMP architecture will >> (or even CAN) transfer an atomic (i.e. aligned) interger in two steps, so >> that A2 + B1 can seem A1 somewhere... I hope at least we have the >> guarantee >> that if we write AAAAFFFF on a 32-bit interger (or any sensible value in >> the architecture domain, like I.E. a 64 bit pointer in a 64 bit machine), >> we hadn't any XXXXFFFF reading anywhere... > > You seriously think that this is a guarantee that it is reasonable to > rely on at the application level in otherwise portable C or C++ code for > the infinitely unforseeable future? > No, I don't. As I said, I NEVER use any shared data in an unlocked state, not even a volatile aligned int, as there's no guarantee etc. etc.... > I can't see this often enough -- you have the guarantees that you > actually have from the relevent standard. Any other assumptions should be > considered platform-specific optimizations. Use them when you are confined > to platforms where you *know*for*sure* that they work. Code the generic > versions first, and optimize only if the need is proven. > > This leads to reliable code, which is good. Google for "premature > optimization". ;) > I 100% agree with you. I only stated that there IS a (platform specific) way to achieve that on any CURRENT platform. I didn't say that there is a STANDARD way to achieve this, nor that there is a COMMON way to do that, just that there is A way to have atomic r/w... or you wounldn't be making mutexes ;-) Actually, when I used the notation: if ( m_owner == ... ) { } ..... I was not meaning C or C++, but some sort of pseudocode. We ( Mr. Dimov and me) assume that m_owner is atomic NOT out of black magic, but once that this is granted on the target platforms by the correct technique. Have I cleared it now? I sense we should have made it clearer sooner, because even if this is "implied" for us, our readers (I mean casual readers passing by) may have intended that this were actual working code. It is always necessary to be extremely precise about threading, and give nothing for granted or "implied". Sorry for that, readers... Giancarlo. . 0