Open colesbury opened 2 weeks ago
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.
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)
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 listFor (2) and (3), 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.