Re: [PATCH 1/2] Add pthread_getname_np and pthread_setname_np

2016-07-29 Thread Jon Turney

On 28/07/2016 20:21, Corinna Vinschen wrote:

Hi Jon,

On Jul 28 12:43, Jon Turney wrote:

This patch adds pthread_getname_np and pthread_setname_np.

These were added to glibc in 2.12[1] and are also present in some form on
NetBSD and several UNIXes.

The code is based on NetBSD's implementation with changes to better match
Linux behaviour.

Implementation quirks:

* pthread_setname_np with a NULL pointer segfaults (as linux)

* pthread_setname_np accepts names longer than 16 characters (linux returns
ERANGE)


Given the behaviour of pthread_getname_np we should do the same, I think.


Ok.




* pthread_getname_np with a NULL pointer returns EFAULT (as linux)

* pthread_getname_np with a buffer length of less than 16 returns ERANGE (as
linux)

* pthread_getname_np truncates the thread name to fit the buffer length.
This guarantees success even when the default thread name is longer than 16
characters, but means there is no way to discover the actual length of the
thread name. (Linux always truncates the thread name to 16 characters)

* Changing program_invocation_short_name changes the default thread name.

I'll leave it up to you to decide any of these matter.

This is implemented via class pthread_attr to make it easier to add
pthread_attr_[gs]etname_np (present in NetBSD and some UNIXes) should it
ever be added to Linux (or we decide we want it anyway).


Good thinking.


Yaakov's idea, not mine :)



Re: [PATCH 2/2] Send thread names to debugger

2016-07-29 Thread Jon Turney

On 28/07/2016 20:34, Corinna Vinschen wrote:

On Jul 28 12:43, Jon Turney wrote:

GDB with the patch from [1] can report and use these names.


This is still WIP, right?


Yes, that's right.


--- a/winsup/cygwin/cygthread.cc
+++ b/winsup/cygwin/cygthread.cc
@@ -213,6 +213,8 @@ cygthread::create ()
this, 0, &id);
   if (!htobe)
api_fatal ("CreateThread failed for %s - %p<%y>, %E", __name, h, id);
+  else
+   SetThreadName(GetThreadId(htobe), __name);

^^^ ^^^
   space?  space?

Just wondering: Wouldn't it make sense to rename the internal threads
so they either always start with "cyg_" or with double underscore or
something like that to mark them as internal?  E.g.


Yeah, I wanted to do something like that.

But messing with the thread names may have other consequences (See 
fhandler_tty.cc:109), and I was a bit wary of introducing a malloc/free 
to into cygthread::create() to dynamically make the name with a "__" 
prepended




Re: [PATCH 2/2] Send thread names to debugger

2016-07-29 Thread Corinna Vinschen
On Jul 29 14:17, Jon Turney wrote:
> On 28/07/2016 20:34, Corinna Vinschen wrote:
> > On Jul 28 12:43, Jon Turney wrote:
> > > GDB with the patch from [1] can report and use these names.
> > 
> > This is still WIP, right?
> 
> Yes, that's right.
> 
> > > --- a/winsup/cygwin/cygthread.cc
> > > +++ b/winsup/cygwin/cygthread.cc
> > > @@ -213,6 +213,8 @@ cygthread::create ()
> > >   this, 0, &id);
> > >if (!htobe)
> > >   api_fatal ("CreateThread failed for %s - %p<%y>, %E", __name, h, id);
> > > +  else
> > > + SetThreadName(GetThreadId(htobe), __name);
> > ^^^ ^^^
> >space?  space?
> > 
> > Just wondering: Wouldn't it make sense to rename the internal threads
> > so they either always start with "cyg_" or with double underscore or
> > something like that to mark them as internal?  E.g.
> 
> Yeah, I wanted to do something like that.
> 
> But messing with the thread names may have other consequences (See
> fhandler_tty.cc:109), and I was a bit wary of introducing a malloc/free to
> into cygthread::create() to dynamically make the name with a "__" prepended

Ok.


Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat


signature.asc
Description: PGP signature