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:<br><br>>>> timeit.timeit('Lock()', 'from threading import Lock')<br>
1.4449114807669048<br><br>>>> timeit.timeit('dict()')<br>0.2821554294221187<br><br>>>> timeit.timeit('list()')<br>0.17358153222312467<br><br><br>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.<br>
<br>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?<br><br>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?<br>
<br>--<br clear="all">Zachary Burns<br>(407)590-4814<br>Aim - Zac256FL<br>Production Engineer<br>Zindagi Games<br>