Re: [PATCH] Include a thread identifier in log messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 22, 2010 at 11:44:42AM -0700, Eric Blake wrote:
> On 11/22/2010 07:10 AM, Daniel P. Berrange wrote:
> > To allow messages from different threads to be untangled,
> > include an integer thread identifier in log messages.
> > 
> > * src/util/logging.c: Include thread ID
> > * src/util/threads.h, src/util/threads.h, src/util/threads-pthread.c:
> >   Add new virThreadSelfID() function
> > * configure.ac: Check for sys/syscall.h
> 
> >  
> > +int virThreadSelfID(void)
> > +{
> > +#if defined(HAVE_SYS_SYSCALL_H) && defined(SYS_gettid)
> > +    pid_t tid;
> > +    tid = syscall(SYS_gettid);
> > +    return (int)tid;
> 
> Bummer that glibc doesn't export gettid(), but this looks correct to me
> for Linux.
> 
> > +#else
> > +    return (int)pthread_self();
> 
> According to POSIX, this is not portable: pthread_t is an opaque type
> and is allowed to be a struct rather than an arithmetic type, in which
> case casting to int will cause a compilation failure.  But in practice:
> pthread_t is integral on Linux, Solaris, and AIX; and a pointer type on
> BSD and Cygwin; therefore, the cast will probably succeed on all
> architectures we might encounter, but it still might not be correct
> (that is, since pthread_equal() is allowed to return true for two
> distinct pointers, merely casting a pointer to int may give different
> ids for the same thread).
> 
> But I'm okay waiting for an actual bug report of this failing to do the
> right thing before we change this code.

Agreed, given that this is only used for outputing a log message,
I don't think the potential problems are worth worrying about at
this point in time.

Daniel

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]