-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Let critical_section work with pymutex #7031
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
Conversation
Based on python/cpython#135899 this'll be supported in 3.14 (and can be backported to 3.13 fairly easily).
That PR got backported to 3.14.0rc1, which was released before you opened this PR? 🤔 |
Yes I know about that now (I hadn't seen rc1 when I posted this). I'll get this finished fairly soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just style comments.
tests/run/critical_sections.pyx
Outdated
threading.Thread(target=worker) | ||
for _ in range(n_threads) | ||
] | ||
for t in threads: | ||
t.start() | ||
for t in threads: | ||
t.join() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used so often, it seems worth a helper function.
Cython/Compiler/Nodes.py
Outdated
mutex = "Mutex" if self.critical_section.is_pymutex_critical_section else "" | ||
|
||
code.putln( | ||
f"__Pyx_PyCriticalSection_End{self.len}(&{variable_name});" | ||
f"__Pyx_PyCriticalSection_End{mutex}{self.len}(&{variable_name});" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use two different macro name suffixes for the two cases, Object
and Mutex
? They seem equivalent and the code already sets the suffix to the empty string explicitly, so it seems easy to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather clean up the macro names a bit to match what CPython uses internally - I've diverged a little and I'm regretting it a little. (That doesn't use Object
)
Based on python/cpython#135899 this'll be supported in 3.14 (and can be backported to 3.13 fairly easily).
Draft for now because I can't easily test this until the next Python release