Logging with threads
Hal Murray
halmurray at sonic.net
Sun Jul 6 17:27:17 UTC 2025
Interesting. Thanks.
> Currently it adds 16 bytes per line logged.
I think 16 is a bit too much.
> The code is pretty simple and I think it should be portable.
> + fprintf(term_file, "%s[%d.%ld]: ", prog, pid,
> (long int)pthread_self());
The Linux man page says that pthread_t might be a struct.
What OS are you running on? I think Linux uses a whole process for each
thread. If you are running on Linux, try using gettid() rather than
getpid(). That shouldn't take any extra space on the printed line.
(Well, an extra space if the value of the ID grows by a digit when
printed.)
--
These are my opinions. I hate spam.
More information about the devel
mailing list