Closed gavv closed 4 years ago
@gavv, what about using uv_thread_self()
?
@dshil it's portable, but, just like pthread_self(), it returns an opaque handle that is not an integral type. It can't be printed, or used to find the thread in ps/top, or used to to send a signal to the thread.
Assigned to @RohanK99.
Problem
It would be convenient to include integral thread identifier in log messages.
Currently messages look like this:
and with thread ID they should look like:
This thread ID can be used to distinguish threads, and, at least on Linux, to find these threads in ps/top and to send signals to them.
Solution
We can use
syscall(SYS_gettid)
on Linux andpthread_getthreadid_np()
on OSX and (in future) on BSD. Both function are non-portable.Steps:
Add
target_linux
andtarget_bsd
to SConstruct.target_linux
should be enabled ifplatform
islinux
orandroid
.target_bsd
should be enabled ifplarform
isdarwin
.Add
core::format_tid()
, similar tocore::format_time()
. It should have two implementations:src/modules/roc_core/target_linux/roc_core/format_tid.cpp
(using SYS_gettid) andsrc/modules/roc_core/target_bsd/roc_core/format_tid.cpp
(using pthread_getthreadid_np).Use
core::format_tid()
incore::Logger::print()
.