Boost logo

Boost :

Subject: [boost] [python] Proposal: RAII for Global Interpreter Lock (GIL)
From: John Zwinck (jzwinck_at_[hidden])
Date: 2012-12-14 12:49:18


There are many questions and example classes online for dealing with
Python's Global Interpreter Lock (GIL) using RAII. I think Boost.Python
should provide this functionality, rather than having users who build
hybrid C++/Python applications copy-pasting code from various places. I
was one of those users recently, and the code I developed to deal with
it is now public:

https://github.com/jzwinck/pccl/blob/master/InterpreterLockGuard.hpp
https://github.com/jzwinck/pccl/blob/master/InterpreterLockGuard.cpp
https://github.com/jzwinck/pccl/blob/master/test/InterpreterLockGuard.test.cpp

Comments in the header explain how to use it in the context of
Boost.Python, and contain a link to a wiki from which some of the code
was originally copied.

Why add this to Boost? It's clearly code that a bunch of people need,
often people who are already using Boost.Python. It has a permissive
license, and I can re-license it if need be. And it depends on Boost
(mostly for thread-specific storage--I hope this dependency won't be
seen as a liability here, though it could be removed if needed).

This particular implementation was used successfully in a few programs
in a commercial setting on Fedora and RHEL systems. It has some extra
checks that we found helpful compared to some of the versions you'll
find posted online. The code also builds and passes its tests with GCC
on Mac OS X.

I welcome any feedback regarding the suitability for inclusion in Boost
of this particular code and/or the concepts it implements.

John Zwinck


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk