mikeash.com pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html commentshttp://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsmikeash.com Recent CommentsThu, 28 Mar 2024 23:15:37 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssRob Harris - 2009-07-15 14:17:50http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#comments<b>Best</b> write-up on "volatile" I've read. "Easy to fix!" false-starts made me laugh out loud.912ce61296c3c13802ccc4e95c7912dcWed, 15 Jul 2009 14:17:50 GMTmikeash - 2009-07-14 22:38:02http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsIt would make no difference. It's still a different value in memory, even if it's part of the same struct. The "as if" rule remains unchanged. The compiler can still make these assignments happen in any order and the result is still "as if" they happened in the order specified by the program.d9e37e0d532d6b2f62cb8aa225d4dc65Tue, 14 Jul 2009 22:38:02 GMTAnonymous - 2009-07-14 19:50:39http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsExcellent series, Mike. One question (that may reveal my ignorance of such things): in the block <br /> <br />gSharedStructure.foo = ...; <br />gSharedStructure.bar = ...; <br />gSharedStructure.baz = ...; <br />gFlag = 1; <br /> <br />would changing the gFlag variable to be part of the structure be enough to make gFlag have the "dependency" on the structure, and thus solve the problem?1ac49ace605dc0cd48826661598ae03aTue, 14 Jul 2009 19:50:39 GMTmikeash - 2009-07-11 08:14:01http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsLockless shared data can be really nice if you do it right. It's just extremely tricky. Certainly it makes a great case for avoiding it if you don't need it, and for minimizing it as much as you can when you do. However, if you can restrict the shared-data code to a single piece of the app (e.g. a reusable data structure) then it's much more sane. You still have to be really really careful in that one section, but once it's up and running you can then use the API it exposes without any worry.974726078c3e3fb104d65ee9f8c0bff6Sat, 11 Jul 2009 08:14:01 GMTCarl Harris - 2009-07-11 05:57:47http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#comments@Carl Harris: s/no much/now much/ <br />363316ad440ba68bc58a6b60620e8674Sat, 11 Jul 2009 05:57:47 GMTCarl Harris - 2009-07-11 05:56:56http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsExcellent series! The details around interleaving and "as if" in both the compiler and the hardware have always been a bit of mystery to me -- no much less so! Of course, the whole of part 3 makes an outstanding case for avoiding the use of lockless shared data altogether. :-)9adbb8f316f72cbed8d39daf646a0381Sat, 11 Jul 2009 05:56:56 GMTnatevw - 2009-07-11 01:55:03http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#comments@mikeash: Thanks, this series has been quite interesting and will be a helpful reference in the future too! <br /> <br />@Steve Madsen: <br />I suspect you might be right, the combination of new language syntax and a helpful runtime in GCD may have a profound influence on many programming tasks. There's a "Technology Brief" linked from the bottom right of the Grand Central marketing blurb here, if you hadn't seen it: <br /><a href="http://www.apple.com/macosx/technology/#grandcentral">http://www.apple.com/macosx/technology/#grandcentral</a> <br />2d7fb9682ec33c934eca2583a45d372cSat, 11 Jul 2009 01:55:03 GMTVyacheslav Zakovyrya - 2009-07-11 00:52:13http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsThanks for this. One more reason to use message passing concurrency to avoid all these troublesa5236aa0b3becf0fed7b259eb55d341bSat, 11 Jul 2009 00:52:13 GMTSteve Madsen - 2009-07-10 22:06:16http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-10-type-specifiers-in-c-part-3.html#commentsThis was an excellent series. This week's brought a smile to my face, having spent several years writing network kernel code and device drivers, sometimes learning the hard way about volatile, memory barriers and instruction reordering. <br /> <br />I don't have the Developer Preview, but I'd put money down that Grand Central in Snow Leopard is going to turn me into an old man ("In my day...").54ad41de0e1745dd95489778f9370bafFri, 10 Jul 2009 22:06:16 GMT