-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-112535: Add test on _Py_ThreadId() #112709
Conversation
@colesbury @corona10: I wrote a short test to spawn 5 threads, call Maybe we can compare |
On FreeBSD x86-64,
|
Same on Linux ppc64le. |
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
d6fc8b8
Compare
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. |
@colesbury: Would you mind to review the updated PR? |
@@ -112,7 +112,7 @@ def test_module_not_found(self): | |||
class WindowsExtensionSuffixTests: | |||
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 "" |
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.
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