In my experience it is far more expensive to allocate a lock in python then it is the types that use them. Here are some examples:
>>> timeit.timeit('Lock()', 'from threading import Lock') 1.4449114807669048 >>> timeit.timeit('dict()') 0.2821554294221187 >>> timeit.timeit('list()') 0.17358153222312467 Granted, I know these types do not allocate a lock - but a similarly defined user type would need to allocate a lock to guarantee thread-safety. I have not done a great deal of research into lockless algorithms thusfar, but would it be worthwhile to investigate implementing some of them in python to optimize performance critical sections of code? Many lockless algorithms that I have looked at thusfar require a "Compare and Swap" operation. Does python have an equivalent to this? Is python high level enough that it has something better than this or it simply doesn't need it? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games
-- http://mail.python.org/mailman/listinfo/python-list