Lockless algorithms in python (Nothing to do with GIL)

Zac Burns zac256 at gmail.com
Mon Jun 28 19:46:41 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100628/d1a0216b/attachment.html>


More information about the Python-list mailing list