threading and multicores, pros and cons

Paul Rubin http
Thu Feb 15 01:32:52 EST 2007


John Nagle <nagle at animats.com> writes:
>      But there are dumb thread implementations that make
> a system call for every lock.

Yes, a sys call on each lock access would really be horrendous.  But I
think that in a modern cpu, LOCK XCHG costs as much as hundreds of
regular instructions.  Doing that on every adjustment of a Python
reference count is enough to impact the interpreter significantly.
It's not just mutating user data; every time you use an integer, or
call a function and make an arg tuple and bind the function's locals
dictionary, you're touching refcounts.

The preferred locking scheme in Linux these days is called futex,
which avoids system calls in the uncontended case--see the docs.



More information about the Python-list mailing list