Skip to content

gh-125996: fix thread safety of ordered dict #133734

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

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

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented May 9, 2025

@kumaraditya303 kumaraditya303 marked this pull request as ready for review May 13, 2025 09:08
@kumaraditya303 kumaraditya303 requested a review from colesbury May 13, 2025 09:08
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

Would you please also provide some timing measurements for basic operations?

register PyODictObject *od = _PyODictObject_CAST(op);
PyDict_Clear(op);
_odict_clear_nodes(od);
PyDict_Clear((PyObject *)self);
Copy link
Contributor

Choose a reason for hiding this comment

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

_PyDict_Clear_LockHeld

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_PyDict_Clear_LockHeld expects the critical section of the dict to be held but here in tp_clear it isn't held so critical section held assertions fail, should I also add the critical section to tp_clear?

Comment on lines +1782 to +1784
#ifndef Py_GIL_DISABLED
Py_CLEAR(di->di_odict);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

If we need to hold a lock for the iterator, we can keep the Py_CLEAR(di->di_odict);

Comment on lines +1846 to +1848
#ifndef Py_GIL_DISABLED
Py_CLEAR(di->di_odict);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Sign up for free to 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.

3 participants