Closed osmeest closed 2 years ago
The simplest way to add support for native threads would be to extend Message::init() and look for native thread attributes when Thread::current() returned nullptr. However, inspecting native thread attributes is going to be OS dependent, just like Thread uses multiple implementations of ThreadImpl depending on the target platform.
A cleaner way would be to split ThreadImpl in 3 parts:
For simplicity sake, NativeThreadImpl could provide stubbed methods for setStackSize and start, since they make no sense for already running threads. Instead of deriving from ThreadImpl, a Thread would contain a NativeThreadImpl (or a ThreadImpl when it is created by Thread constructor).
There is pull request #3017 that also introduces patterns for native threads.
The proposals made in pull request #3017 add a new pattern for the OS specific thread id. In the meantime, I've developed the simpler solution described above (NativeThreadInfo capable of reading id & name + platform specific implementations). It's implemented and unit tested for POSIX. I also provided blind implementations for Windows and VxWorks. Not sure how to proceed in checking those.
Corresponding pull request #3333
Given that there are multiple proposals for the OS-native thread id (%O in #3017) and %I in the existing pattern, which direction do you intend to take in r1.12.0 ?
%J
it is
%J is ok for the OS thread id (gettid()). But what about the thread name (pthread_getname_np()) ?
PatternFormatter provides %T and %I to print the thread name and thread id. Those patterns depend on attributes of Message which are set in the init() function, using Thread::current() and calling getName() and getTid() on the thread if any. Since Thread::current() works only for a thread that has been created using Poco::Thread, it does not work for threads that were created in another library (eg. std::thread).