python / python/cpython

PyMutex re-entrancy not documented, confusing existing doc

未關閉
#146,536 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

docs
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Documentation

The doc for PyMutex is very unclear if the mutex is re-entrant. Can PyMutex_Lock be called multiple times in the same thread? Do there have to be an equal number of PyMutex_Unlock calls?

The PyMutex_Lock doc says it will succeed if the thread already has the lock. PyMutex_Unlock makes no mention of it having to be called in the same thread, or if any thread is okay.

Elsewhere it says the mutex is one byte, which is not enough to do any form of counting.

The relevance is that I have C code wrapping a library and that library can make callbacks. That means there are multiple paths through the call stack. A re-entrant counting mutex would work perfectly, and it is impossible to use a non-counted lock in that scenario, short of implementing another layer of locking to do the counting.

Linked PRs
  • gh-146543

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 C 同步文件中的 PyMutex API 參考開始,並檢視連結的 PR gh-146543。確定重複呼叫 PyMutex_Lock 時文件所記載的行為,以及 PyMutex_Unlock 所需的執行緒和呼叫次數,然後更新文件,明確說明這些規則。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
documentation
Issue 類型
文件
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。