Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-112535: Add test on _Py_ThreadId()#112709
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
vstinner commented Dec 4, 2023 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented Dec 4, 2023
@colesbury@corona10: I wrote a short test to spawn 5 threads, call Maybe we can compare |
vstinner commented Dec 4, 2023
On FreeBSD x86-64, |
vstinner commented Dec 4, 2023
Same on Linux ppc64le. |
colesbury left a comment
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 having a test for _PyThread_Id() is good, but I I don't think we should bother comparing with _thread.get_ident().
I think we want the following:
_PyThread_Id()should be unique and non-zero_PyThread_Id()should not change for a given thread. For example, it should remain the same after a short sleep.- It should be a multiple of four (i.e., at least 4-byte aligned). This isn't necessary for biased reference counting, but it makes implementing recursive mutexes easier and should be true for all our implementations of it.
| get_py_thread_id(PyObject *self, PyObject *type) | ||
| { | ||
| uintptr_t tid = _Py_ThreadId(); | ||
| Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(tid)); |
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.
You can just use C11 static_assert() now, which has better error messages.
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.
Py_BUILD_ASSERT() doesn't require an error message which makes my life easier, I don't have to write down an error message :-)
Add also test.support.Py_GIL_DISABLED constant.
bf6b57b to d6fc8b8Comparevstinner commented Dec 4, 2023
Ok, I removed this test.
I added tests for that.
I will let you add a check for that later (in a following PR). I prefer to add tests step by step, especially if it's not strictly needed right now. |
vstinner commented Dec 4, 2023
@colesbury: Would you mind to review the updated PR? |
| def test_tagged_suffix(self): | ||
| suffixes = self.machinery.EXTENSION_SUFFIXES | ||
| abi_flags = "t" if sysconfig.get_config_var("Py_GIL_DISABLED") else "" | ||
| abi_flags = "t" if support.Py_GIL_DISABLED else "" |
colesburyDec 4, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
@vstinner - looks like Windows tests are failing (possibly due to missing import for support:
https://github.com/python/cpython/actions/runs/7090430380/job/19297369118?pr=112709
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.
Ah right, I saw it before. Thanks for the reminder. It should now be fixed.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Donghee Na <[email protected]>
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
_Py_ThreadId()work on PowerPC, IBM Z, etc. #112535