Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Race inThread.join() #116372

Closed
Closed
Assignees
mpage
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@mpage

Description

@mpage

Bug report

Bug description:

There is a race between whenThread._tstate_lock is released1 inThread._wait_for_tstate_lock() and whenThread._stop() asserts2 that it is unlocked. Consider the following execution involving threads A, B, and C:

  1. A starts.
  2. B joins A, blocking on its_tstate_lock.
  3. C joins A, blocking on its_tstate_lock.
  4. A finishes and releases its_tstate_lock.
  5. B acquires A's_tstate_lock in_wait_for_tstate_lock(), releases it, but is swapped out before calling_stop().
  6. C is scheduled, acquires A's_tstate_lock in_wait_for_tstate_lock() but is swapped out before releasing it.
  7. B is scheduled, calls_stop(), which asserts that A's_tstate_lock is not held. However, C holds it, so the assertion fails.

The race can be reproduced3 by inserting sleeps at the appropriate points in the threading code. To do so, run therepro_join_race.py from the linked repo.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Footnotes

  1. https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1201

  2. https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1115

  3. https://github.com/mpage/cpython/commit/81946532792f938cd6f6ab4c4ff92a4edf61314f

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp