File tree Expand file tree Collapse file tree 1 file changed +1
-22
lines changed
Expand file tree Collapse file tree 1 file changed +1
-22
lines changed Original file line number Diff line number Diff line change @@ -410,28 +410,7 @@ that point, a deadlock can occur.
410410If your extension type needs its own lock, add a separate :c:type: `PyMutex `
411411field (or another synchronization primitive) to your object struct.
412412:c:type: `PyMutex ` is very lightweight — it is only one byte — so there is
413- negligible cost to having an additional one::
414-
415- /* WRONG — do not lock ob_mutex directly */
416- PyMutex_Lock(&obj->ob_mutex);
417- ...
418- PyMutex_Unlock(&obj->ob_mutex);
419-
420- /* RIGHT — use critical sections for ob_mutex */
421- Py_BEGIN_CRITICAL_SECTION(obj);
422- ...
423- Py_END_CRITICAL_SECTION();
424-
425- /* RIGHT — use your own mutex for your own state */
426- typedef struct {
427- PyObject_HEAD
428- PyMutex my_mutex; /* separate lock for extension state */
429- int my_data;
430- } MyObject;
431-
432- PyMutex_Lock(&self->my_mutex);
433- self->my_data++;
434- PyMutex_Unlock(&self->my_mutex);
413+ negligible cost to having an additional one.
435414
436415
437416Building Extensions for the Free-Threaded Build
You can’t perform that action at this time.
0 commit comments