nogil inconsistent empty list while sorting
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Hi,
We're a research group focused on testing concurrent runtimes. Our work-in-progress prototype found a violation of atomicity on the current nogil build when using concurrent operations on the same list. The program below shows the wrong behavior.
from threading import Thread,Barrier,Lock
def t1(b1,l,r):
b1.wait()
r[0] = l.__len__()
def t2(b1,l,r):
b1.wait()
r[0] = l.__str__()
def t3(b1,l):
b1.wait()
l.sort()
def normalSetTest(i):
sharedList = [1,2,3] * 100
barrier = Barrier(2)
res = [ None ]
threads = [
Thread(target= t1, args=(barrier,sharedList,res,)),
#Thread(target= t2, args=(barrier,sharedList,res,)),
Thread(target= t3, args=(barrier,sharedList,)),
]
for t in threads:
t.start()
for t in threads:
t.join()
if res[0] in [ 0, '[]' ]:
print("\tfound bug: " + str(res[0]))
print("test begin...")
for n in range(0,10):
threads = []
for i in range(0,1):
threads.append(Thread(target= normalSetTest, args=(n,)))
for t in threads:
t.start()
for t in threads:
t.join()
print("test Done")
A list with 300 integers is sorted in t3 while another thread either gets the size of the list t1 or turns the list into a string t2. Running the code above will show threads t1 and t2 finding an inconsistent empty list with length 0 or turned into the string "[]".
Our tool did not find any other interesting values: either it's an expected value (original list or sorted list) OR it's empty.
Sample output:
test begin...
found bug: 0
found bug: 0
found bug: 0
found bug: 0
found bug: 0
test Done
We're happy to provide more details about this bug, and to help developers reproducing it.
Output of python -VV: Python 3.14.0a1+ experimental free-threading build (heads/main:faa3272fb8d, Oct 29 2024, 09:14:25) [GCC 14.2.1 20240805]
@flypoodles and @overlorde are part of the team, adding them so they get notified about further discussion.
I believe this issue is part of the ongoing conversation on #126136 about acceptable behaviors of containers operated by many threads concurrently, described in the original nogil PEP: https://peps.python.org/pep-0703/#container-thread-safety
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された再現プログラムを free-threading CPython ビルドで実行し、次に PEP 703 のコンテナのスレッドセーフティに関するセクションと issue #126136 の議論を読んでください。リストの並行ソート、長さの取得、文字列変換について期待される動作を確定してから、修正とリグレッションテストが必要かどうかを判断する必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100