-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncio
thread-safety issues in the free-threaded build
#120974
Comments
I think that the pure Python fallback isn't thread safe either, FWIW I think there are more thread safety issues than these, asyncio code was written with assumption of GIL. |
Yeah, but for landing PEP 703, we are trying to change modules, not depending on the GIL, even if we need to re-write some parts of the implementation with a conditional flag. (If the new written part requires some performance overhead) |
This refactors asyncio to use the common freelist helper functions and macros. As a side effect, the freelist for _asyncio.Future is now re-enabled in the free-threaded build.
…d build Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock.
…d build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate.
#122138) Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock.
…d build (pythonGH-122138) Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock. (cherry picked from commit 47847aa) Co-authored-by: Sam Gross <[email protected]>
This refactors asyncio to use the common freelist helper functions and macros. As a side effect, the freelist for _asyncio.Future is now re-enabled in the free-threaded build.
…d build (pythonGH-122139) * pythongh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate. (cherry picked from commit a15fede) Co-authored-by: Sam Gross <[email protected]>
…ed build (GH-122139) (#122186) gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (GH-122139) * gh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate. (cherry picked from commit a15fede) Co-authored-by: Sam Gross <[email protected]>
…d build (python#122138) Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock.
This refactors asyncio to use the common freelist helper functions and macros. As a side effect, the freelist for _asyncio.Future is now re-enabled in the free-threaded build.
…d build (python#122139) * pythongh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate.
…d build (python#122138) Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock.
This refactors asyncio to use the common freelist helper functions and macros. As a side effect, the freelist for _asyncio.Future is now re-enabled in the free-threaded build.
…d build (python#122139) * pythongh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate.
…ed build Use a critical section around the modifications to `current_tasks`.
…ed build Use a critical section around the modifications to `current_tasks`.
…ed build (pythonGH-122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build (cherry picked from commit b5e6fb3) Co-authored-by: Sam Gross <[email protected]>
…ed build (python#122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build
Make `_asyncio.all_tasks` thread safe, also changes state lock to use critical section.
…ed build (python#122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build
Make `_asyncio.all_tasks` thread safe, also changes state lock to use critical section.
Bug report
fi_freelist
isn't thread-safe (move topycore_freelist.h
and follow that pattern)enter_task
,leave_task
, andswap_current_task
aren't thread-safe due to sharedstate->current_tasks
and borrowed references.register_task
andunregister_task
aren't thread-safe due to sharedstate->asyncio_tasks
linked list_asyncio_all_tasks_impl
isn't thread-safe due the theasyncio_tasks
linked list.For 2, 3, and 4, we can consider using critical sections to protect the accesses to
state->current_tasks
andstate->asyncio_tasks
.Longer term, moving data to per-loop will probably help with multi-threaded scaling.
Linked PRs
swap_current_task
safe in free-threaded build #122317swap_current_task
safe in free-threaded build (GH-122317) #122612The text was updated successfully, but these errors were encountered: