Skip to content
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

Use PyWeakref_GetRef and critical section in BlockValuesRefs #60540

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lysnikolaou
Copy link
Contributor

@lysnikolaou lysnikolaou requested a review from WillAyd as a code owner December 11, 2024 15:08
@lysnikolaou lysnikolaou force-pushed the lock-block-values-refs branch from 4e28feb to e21c3c9 Compare December 11, 2024 15:10
@@ -927,8 +935,9 @@ cdef class BlockValuesRefs:
blk : Block
The block that the new references should point to.
"""
self._clear_dead_references()
self.referenced_blocks.append(PyWeakref_NewRef(blk, None))
with cython.critical_section(self):
Copy link
Member

Choose a reason for hiding this comment

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

For the uninformed what does the critical section do? Grab hold of the GIL or some other global mutex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A critical section is a per-object lock (here we're locking self, so an instance of BlockValuesRefs) that has a deadlock avoidance mechanism on top of it. More info on the Python docs.

@rhshadrach rhshadrach added Enhancement Build Library building on various platforms Python 3.13 labels Dec 27, 2024
@jbrockmendel
Copy link
Member

Perf impact?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Library building on various platforms Enhancement Python 3.13
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants