cpython icon indicating copy to clipboard operation
cpython copied to clipboard

asyncio module state should be locked with mutexes in free-threaded builds

Open Fidget-Spinner opened this issue 1 year ago • 1 comments

Feature or enhancement

Proposal:

Please see issue title.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-121622
  • gh-121695
  • gh-121774

Fidget-Spinner avatar Jul 11 '24 12:07 Fidget-Spinner

I think we also want to make enter_task, leave_task, and swap_current_task behave atomically. For example, enter_task makes two dict API calls that individually lock the dictionary, but the combined operation isn't atomic.

I can think of two strategies for this:

  1. Try to replace multiple API calls with a single call. For example, I think enter_task may be able to use PyDict_SetDefaultRef and leave_task may be able to use _PyDict_DelItemIf with some modifications.
  2. Use a critical section to lock the dict and use the "lock held" variants.

colesbury avatar Jul 11 '24 14:07 colesbury

Fixed.

Fidget-Spinner avatar Jul 22 '24 16:07 Fidget-Spinner