| ||||
| Comment on GotW #91 Solution: Smart Pointer Parameters by earwicker
@GregM – re: “data races with your smart pointer” – this is about shared_ptr, not any old smart pointer. The standard shared_ptr is in fact thread-safe w.r.t. assignment. This is why it is so slow, which in turn is why Herb is so keen on discouraging patterns where shared_ptr gets copied a lot. And in any case, re: the part I’m questioning, why bring threads into it? Herb (correctly) does not..His “2. What are the correctness implications…” makes no mention at all of data races or multiple threads, and nor does it need to: it’s about the relationship between variables declared at different places in a single call/variable stack, such as is found in a single-threaded C++ program. Herb: “Even if we passed the shared_ptr by reference, our function would as good as hold a strong refcount because the caller already has one—he passed us the shared_ptr in the first place, and won't release it until we return. (Note this assumes the pointer is not aliased… in this respect it's no different than any other aliased object.)” That guarantee (including the disclaimer-in-brackets that sadly undermines it) is all about a single thread. My point is that it’s about as helpful as: Me: “If I hold a single red rose between my teeth, you and I can tango into the Room of Poison Gas without dying! (Assuming of course that there’s no poison gas in the room at this particular moment – but hey, poison gas is generally dangerous so why should this little tacked-on caveat be any kind of surprise?)” Read More »Comment on My //build/ talk on Friday @ noon PDT (webcast) by RC
@Olaf van der Spek: At my company, products will standardize on a compiler per platform, meaning for instance VS2010 for Windows. Updates are fine (thanks to the commitment from the MSVC team not to break anything in updates), but upgrades are not. We are on MSDN subscriptions, so cost is not really an issue for us at least (can’t speak for jalf of course). Hopefully we will be able to update the policy per product more often now that VS will update faster, but we don’t know that yet. We may soon standardize on VS2012 (currently VS2010, before that VS2005), VS2013 won’t happen until maybe next year or a year from that or may be skipped entirely in favor of later releases. With that said, I think that Herb and the MSVC team get too much heat from the community – of course I would want all of C++11 to be available now, but we need to be realistic about what can be achieved. Doing updates for both VS2012 and VS2013 increases the burden on the team and would therefore just slow things down. I appreciate the efforts from the compiler team and the commitment to more transparency. The roadmap was great to see and will help us make engineering decisions on what we can expect to use for the coming years. Read More »Comment on GotW #91 Solution: Smart Pointer Parameters by GregM
Okay, fine, so leave threads out of it. If you call some other function that does something to the object that you’re working on, then it’s still a problem. This same problem exists whether you have a copy of the shared_ptr or a reference to the shared_ptr. The copy of the shared_ptr only gives you additional safety against the object being destroyed if there is someone else that has a non-const reference to the shared_ptr itself. In that case, however, it still gives you no safety against changes in the object itself. If you and your caller both have a pointer to the object, but so does someone else, and you call that someone else to do something, and it, unknown to you, changes all the data in that object, how has the copy of the shared_ptr helped you? Analogies don’t generally work very well, but let me give it a shot with what you used. Say that you are holding a single red rose between your teeth, and I’m holding your hand. The other person who is also holding the same single red rose between their teeth can bite through the stem and ruin the rose. My holding the rose between my teeth in addition to holding your hand doesn’t prevent the other person from biting through the stem. If you want the other person to not be able to bite through the stem, you better make sure that they don’t have it between their teeth. It won’t make a bit of difference how I hold the rose. Since you’re holding the rose between your teeth, and you are frozen until I go away, then I know that you can’t open your mouth and drop the rose. I can either simply hold your hand, or I can hold your hand and also hold the rose between my teeth, and the rose won’t be dropped on the ground no matter what happens. Read More » | ||||
| ||||
Thursday, July 4, 2013
FeedaMail: Comments for Sutterâs Mill
Subscribe to:
Comments (Atom)