|
|||||||||||
|
Re: Eyeballs needed on new reference counted pointer template
From: Jonathan Wakely <mysql(at)kayari.org>
Date: Fri Aug 17 2007 - 20:54:45 EDT
The example wasn't picked entirely randomly :-) In a single-threaded program you don't have to worry about a Row object being destroyed while another thread uses it. If you are foolish enough to share Rows between threads, you must ensure no thread is still using it when it is deleted or goes out of scope. So those brave people doing this must already synchronise access to shared Rows (and Results, and Connections ...) and I don't think you need to do any additional synchronisation. > This comes up when someone runs a query, gets some Rows, then wants to I think your RefcountedPointer is a great solution. > The atomic inc/dec issue brought up by Joseph Artsimovich is all that I agree. It would be a bad idea to make all operations on Rows "atomic" (I think the only way would be to acquire a per-Connection mutex for most operations, which would be useless and expensive in 99.9% of cases, where people don't share objects across threads anyway) > So, tell me why I'm wrong. Why is it helpful to send off Rows to a I don't think it is useful, but it's not only that scenario you have to worry about. Two threads could both call Row::at(int) on Row objects of the /same/ query result, and there's a race on the memory allocation in ResUse::field_types(int). You can't prevent that without unreasonable effort, so users must do their own synchronisation already. Making RefCountedPointer atomic wouldn't help, and would make it significantly slower. > > I think the latest Boost.SharedPtr actually uses a pointer to member Honestly, I don't know the benefits, but if it's good enough for Peter Dimov (the shared_ptr maintainer and expert) then it's good enough for me, so I'd copy Boost. Either is better than implicit conversion to bool :-) > > With a safe bool there's no need for operator! You're right, it was never needed technically ... but if there's a portability reason I see no problem with keeping it, as long as it uses the same logic as the safe bool conversion. Jon -- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=lists@pantek.comReceived on Fri Aug 17 20:54:58 2007 This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 10:03:04 EDT |
||||||||||
|
|||||||||||