Skip to content

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

Merged
merged 7 commits into from
Jul 26, 2025

Conversation

da-woods
Copy link
Contributor

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

Based on python/cpython#135899 this'll
be supported in 3.14 (and can be backported to 3.13 fairly easily).
@h-vetinari
Copy link
Contributor

Draft for now because I can't easily test this until the next Python release

That PR got backported to 3.14.0rc1, which was released before you opened this PR? 🤔

@da-woods
Copy link
Contributor Author

Draft for now because I can't easily test this until the next Python release

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

@da-woods da-woods marked this pull request as ready for review July 25, 2025 18:22
@da-woods da-woods added this to the 3.2 milestone Jul 25, 2025
Copy link
Contributor

@scoder scoder left a 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.

Comment on lines 255 to 262
threading.Thread(target=worker)
for _ in range(n_threads)
]
for t in threads:
t.start()
for t in threads:
t.join()
Copy link
Contributor

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.

Comment on lines 9105 to 9108
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});"
Copy link
Contributor

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.

Copy link
Contributor Author

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)

@da-woods da-woods enabled auto-merge (squash) July 26, 2025 20:12
@da-woods da-woods merged commit e7139a8 into cython:master Jul 26, 2025
76 of 77 checks passed
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