Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a race between ``PyParkingLot_Park`` and ``_PyParkingLot_UnparkAll``.
6 changes: 5 additions & 1 deletion Python/parking_lot.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,18 @@ _PyParkingLot_Unpark(const void *addr, _Py_unpark_fn_t *fn, void *arg)
void
_PyParkingLot_UnparkAll(const void *addr)
{
struct llist_node *node;
struct llist_node head = LLIST_INIT(head);
Bucket *bucket = &buckets[((uintptr_t)addr) % NUM_BUCKETS];

_PyRawMutex_Lock(&bucket->mutex);
dequeue_all(bucket, addr, &head);
llist_for_each(node, &head) {
struct wait_entry *waiter = llist_data(node, struct wait_entry, node);
waiter->is_unparking = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks correct, but let's push the waiter->is_unparking assignment into dequeue_all and dequeue to avoid the extra loop here.

}
_PyRawMutex_Unlock(&bucket->mutex);

struct llist_node *node;
llist_for_each_safe(node, &head) {
struct wait_entry *waiter = llist_data(node, struct wait_entry, node);
llist_remove(node);
Expand Down