returning a value from a thread

David Bolen db3l at fitlinxx.com
Mon Jul 19 11:37:48 EDT 2004


Antoon Pardon <apardon at forel.vub.ac.be> writes:

> Thanks for the explanation.
> 
> I still have a question. Is the GIL necessary even if there is
> no sharing of data between threads?

Yes, because the GIL's primary purpose is to protect the Python
interpreter itself, and not the application.  That is, the GIL ensures
the integrity of the Python interpreter state, and the state of
individual objects managed by the C core code.

Without the GIL, problems such as that envisioned by the prior poster
(a dictionary becoming internally inconsistent) could certainly arise.

You can approach this problem in other ways than a GIL (e.g.,
fine-grained object resource locks), but as many historical threads
have discussed, the GIL has proven to be a reasonable trade-off in
reliability, including maintainability, and performance - albeit with
a significant con with respect to SMP.  Attempts to implement
fine-grained locking haven't generally panned out to the point where
its worth switching.

-- David



More information about the Python-list mailing list