mardi 14 avril 2020

C++11: is there any user-relatable thread ID?

I'm on g++ version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) running on Fedora release 31 (Thirty One). I'm linking with -pthread.

cout << std::thread:get_id() prints numbers like 140737177954048 . However GDB outputs thread numbers like 2. Is GDB outputting some other ID I too could be outputting? The use is to put thread IDs of the thread generating a log message into the log file so that they can be followed later for debugging, and these 15-digit numbers are likely too hard to read and track as well as taking up a lot of room.

My alternative was to have the log module detect new threads and simply assign an sequentially-incrementing number (atomic<unsigned int> that I CAS). The app in question only has long-lived threads, so I needn't worry about near-infinite numbers of short-lived threads pumping up this counter to unreadable value levels. But if there's something better let me know!

Aucun commentaire:

Enregistrer un commentaire