@@ -151,23 +151,26 @@ Copyright (C) 1994 Steen Lumholt.
151151 interpreter lock was used for this. However, this causes problems when
152152 other Python threads need to run while Tcl is blocked waiting for events.
153153
154- To solve this problem, a separate lock for Tcl is introduced. Holding it
155- is incompatible with holding Python's interpreter lock. The following four
156- macros manipulate both locks together.
154+
155+ To solve this problem, a separate lock for Tcl is introduced.
156+ We normally treat holding it as incompatible with holding Python's
157+ interpreter lock. The following macros manipulate both locks together.
157158
158159 ENTER_TCL and LEAVE_TCL are brackets, just like Py_BEGIN_ALLOW_THREADS and
159160 Py_END_ALLOW_THREADS. They should be used whenever a call into Tcl is made
160161 that could call an event handler, or otherwise affect the state of a Tcl
161162 interpreter. These assume that the surrounding code has the Python
162- interpreter lock; inside the brackets, the Python interpreter lock has been
163- released and the lock for Tcl has been acquired .
163+ interpreter lock: ENTER_TCL releases the Python lock, then acquires the Tcl
164+ lock, and LEAVE_TCL does the reverse .
164165
165166 Sometimes, it is necessary to have both the Python lock and the Tcl lock.
166- (For example, when transferring data from the Tcl interpreter result to a
167- Python string object.) This can be done by using different macros to close
168- the ENTER_TCL block: ENTER_OVERLAP reacquires the Python lock (and restores
169- the thread state) but doesn't release the Tcl lock; LEAVE_OVERLAP_TCL
170- releases the Tcl lock.
167+ (For example, when transferring data between the Tcl interpreter and/or
168+ objects and Python objects.) To avoid deadlocks, when acquiring, we always
169+ acquire the Tcl lock first, then the Python lock. The additional macros for
170+ finer lock control are: ENTER_OVERLAP acquires the Python lock (and restores
171+ the thread state) when already holding the Tcl lock; LEAVE_OVERLAP releases
172+ the Python lock and keeps the Tcl lock; and LEAVE_OVERLAP_TCL releases the
173+ Tcl lock and keeps the Python lock.
171174
172175 By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event
173176 handlers when the handler needs to use Python. Such event handlers are
0 commit comments