Skip to content

Conversation

@kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Feb 9, 2025

Store the current running task on the thread state, it makes it thread safe for the free-threading build and while improving performance as there is no lock contention, this effectively makes it lock free.
When accessing the current task of the current running loop in current thread, no locking is required and can be acessed without locking.
In the rare case of accessing current task of a loop running in a different thread, the stop the world pauses is used in free-threading builds to stop all other running threads and find the task for the specified loop.

This also makes it easier for external introspection to find the current task, and now it will be always correct.

Comment on lines +3891 to +3892
// Fast path for the current running loop of current thread
// no locking or stop the world pause is required
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful.

@kumaraditya303 kumaraditya303 enabled auto-merge (squash) February 19, 2025 16:12
@kumaraditya303 kumaraditya303 merged commit 660f126 into python:main Feb 19, 2025
41 checks passed
@kumaraditya303 kumaraditya303 deleted the per-thread-cur-task branch February 19, 2025 16:35
Copy link
Member

@1st1 1st1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post merge: lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants