Multi-threading on Multi-CPU machines

anton wilson anton.wilson at camotion.com
Tue Jul 9 09:52:59 EDT 2002


> With a multithreaded approach you might keep the array in memory
> and have the main thread farm out work requests to worker threads
> via a bounded queue.  You want the queue a bit larger than the
> number of worker threads, and you can determine the optimal size
> for a work request (could be one item, or maybe two, or, say, 4)
> via some benchmarking.  Upon receiving a work request from the
> Queue, a worker thread would:
>         -- get a local copy of the relevant points from the
>            large array,
>         -- enter the C-coded computation function which
>            -- releases the GIL,
>            -- does the computations getting the nes points,
>            -- acquires the GIL again,


If the bounded queue were declared in a C extention module, would a thread 
doing the calculations really have to reaquire the GIL everytime that thread 
accessed this C data structure? Could mutexes be used instead?


>         -- put back the resulting new points to the same area
>            of the large array where the input came from,
> then go back to peel one more work request from the Queue.





More information about the Python-list mailing list