-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Thread_POSIX.cpp shouldn't convert thread IDs to long #3857
Comments
@arrowd I think there should be a warning and return 0; discarding any OS except Linux and MacOS over this is a too harsh measure |
On FreeBSD specifically you can add a case using this:
defined in |
The point is that an ID returned from |
I do agree pthread_self() shouldn't be used as a numerical thread id since it's not intended to be used that way. pthread_getthreadid_np() on the other hand does return the unique numerical id of the thread. |
It is still a different thing compared to |
I was not aware of the
thr_self() seems like the better option given that it better matches the Linux version, and returns a long rather than int (in the unlikely case thread id would exceed a signed int). https://github.com/freebsd/freebsd-src/blob/d4a80d21b3d32a2de02d1820cc1f38dba1f127cb/sys/kern/kern_thr.c#L297 |
This issue is stale because it has been open for 365 days with no activity. |
…ong #3857; FreeBSD build errors fixes
* fix(Thread_POSIX): Thread_POSIX.cpp shouldn't convert thread IDs to long #3857; FreeBSD build errors fixes * chore(StreamTokenizerTest): fix warnings * fix(build): FreeBSD config * fix(ThreadTest): some tests checking nothing; temporatily comment FreeBSD threadStackSize test (segfaults on pthread_join) * fix(Thread_POSIX): handle emscripten in currentOsTidImpl * chore: fix emscripten define * chore: fix some clang warnings; add sanitizer flag to FreeBSD linux compat build config
* fix(Thread_POSIX): Thread_POSIX.cpp shouldn't convert thread IDs to long #3857; FreeBSD build errors fixes * chore(StreamTokenizerTest): fix warnings * fix(build): FreeBSD config * fix(ThreadTest): some tests checking nothing; temporatily comment FreeBSD threadStackSize test (segfaults on pthread_join) * fix(Thread_POSIX): handle emscripten in currentOsTidImpl * chore: fix emscripten define * chore: fix some clang warnings; add sanitizer flag to FreeBSD linux compat build config
According to the POSIX standard returning value of
pthread_self()
is opaque and can't be casted tolong
. See NOTES section of pthread_self(3) and pthread_equal(3) man pages.The code of
ThreadImpl::currentOsTidImpl()
causes compilation to fail on FreeBSD withOn the other hand, the method is called
currentOsTidImpl
and on Linux it callsgettid()
syscall. If this method is intended to return kernel thread identifier, then the#else
case shouldn't callpthread_self()
and instead have#error Implement this for your OS
. I'm happy to prepare a pull request if my analysis is right.The text was updated successfully, but these errors were encountered: