Skip to content

gh-112087: Update list impl to be thread-safe with manual CS - #113863

Merged
corona10 merged 3 commits into
python:mainfrom
corona10:gh-112087-part2
Jan 16, 2024
Merged

gh-112087: Update list impl to be thread-safe with manual CS#113863
corona10 merged 3 commits into
python:mainfrom
corona10:gh-112087-part2

Conversation

@corona10

@corona10corona10 commented Jan 9, 2024

Copy link
Copy Markdown
Member

@corona10

Copy link
Copy Markdown
MemberAuthor

The rest of the parts can be separated into two parts.
A. xxx_lock implementations.
B. Where PyList_FetchItem is needed.

A is a headache; atomic operation with default build will require some overhead than pure operation; not sure how we can solve this with a seamless approach.

B is quite simple; if we already have similar APIs, then we can just use them. If not, we should introduce one.

@colesburycolesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good other than the unused variable.

I scanned through listobject.c and it looks like there are still other functions that should be fairly straightforward to make thread-safe, such as list_copy_impl and list_append.

What do you mean by "xxx_lock implementations"?

Comment threadObjects/listobject.c
Comment threadObjects/listobject.c
@corona10

Copy link
Copy Markdown
MemberAuthor

@colesbury Updated PTAL :)

@corona10

Copy link
Copy Markdown
MemberAuthor

What do you mean by "xxx_lock implementations"?

It was about list_item_locked things that you updated implementations to use _Py_atomic_store/load operations.

@colesburycolesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

I wonder if it's worth doing something to abstract out the locking in type slots (like tp_richcompare).

@corona10

Copy link
Copy Markdown
MemberAuthor

I wonder if it's worth doing something to abstract out the locking in type slots (like tp_richcompare).

It might be up to case, list_richcompare was too complex case to handle without extracting core logics.

@corona10
corona10 merged commit 42b90cf into python:mainJan 16, 2024
@corona10
corona10 deleted the gh-112087-part2 branch February 15, 2024 01:41
Sign up for freeto 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.

2 participants

@corona10@colesbury