threading support in python

Paul Rubin http
Wed Sep 6 03:28:07 EDT 2006


"sjdevnull at yahoo.com" <sjdevnull at yahoo.com> writes:
> You can, absolutely.  If you're sharing memory through mmap it's
> usually the preferred solution; fcntl locks ranges of an open file, so
> you lock exactly the portions of the mmap that you're using at a given
> time.

How can it do that without having to touch the PTE for every single
page in the range, which might be gigabytes?  For that matter, how can
it do that on regions smaller than a page?  And how does another
process query whether a region is locked, without taking a kernel trap
if it's locked?  This sounds absolutely horrendous compared to a
futex, which should usually be just one or two user-mode instructions
and no context switches.

> It's not an unusual use at all, Unix programs have used file locks in
> this manner for upwards of a decade--things like the Apache public
> runtime use fcntl or flock for interprocess mutexes, and they're quite
> efficient.  (The futexes you mentioned are a very recent Linux
> innovation).

Apache doesn't use shared memory in the same way that something like a
database does, so maybe it can more easily tolerate the overhead of
fcntl.  Futex is just a somewhat standardized way to do what
programmers have done less portably since the dawn of multiprocessors.



More information about the Python-list mailing list