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

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



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


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