Re: Total Ordering?
On Jan 15, 2010, at 3:08 PM, David McClain wrote:
> The only sure fire way I can come up with, sadly a bit slow, is to keep a hash table, and on-demand, enter new objects of interest into the table along with a consecutively incrementing integer value. The hash table is only for the sake of speedy lookups. An association list does the same thing for you, only slower. The important thing is the consecutive integer value. And since we really don't need all Lisp objects, only those of local interest, the table won't grow too long.
>
> It just takes a bit of overhead on each use of an interesting object to find out whether it already has an assigned ID, and if not, generate one and record in the hash table.
>
> I was playing around with STM here, and that sort of overhead really drags on STM performance. So to counteract it, we can record identities on STM object creation, rather than for each time they are used. But in that case, we might as well create a Class structure that contains the ID alongside the Lock, so we don't have to do any lookup at STM runtime.
This is more or less what I had come up with as well. Glad to know I wasn't the only one thinking along these lines.
Just out of curiosity, what sort of performance improvement (if any) do you get using ordered mp:locks in your application as compared to simply having a single symbol-locking-macro - for example:
(eval-when (:compile-toplevel :load-toplevel :execute)
(sys:define-symbol-locking-macro atomically
#.(gensym "ATOMICALLY-SYBOL-LOCKING-GENSYM")))
And then just using:
(atomically (code-that-would-otherwise-take-locks-in-order-to-prevent-livelock...
I ask because in my testing, even with up to 20 threads contending for a single sys:symbol-locking-macro it is still much faster than taking just 3 ordered locks. Taking more ordered locks is even slower.
warmest regards,
Ralph
Raffael Cavallaro
raffaelcavallaro@me.com