[PATCH] Add pthread_getname_np, pthread_setname_np

Yaakov (Cygwin/X) yselkowitz@users.sourceforge.net
Fri Feb 24 03:38:00 GMT 2012


This patchset 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.  IIUC recent versions of GDB can benefit from
this support.

The code is based on NetBSD's implementation with changes to better
match Linux behaviour.  It does differ from Linux in two points:

* The thread name is not affected by changing __progname (or
program_invocation_short_name on Linux).  I used the latter because it
is cheaper than the pinfo->progname dance (e.g. in
format_process_stat()).

* pthread_setname_np(thr, NULL) segfaults on Linux (and NetBSD), but our
snprintf is apparently more robust and treats it as an empty string.

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

I implemented this 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).

Patches and test code attached.


Yaakov

[1] http://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygwin-pthread_getname_np.patch
Type: text/x-patch
Size: 6313 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20120224/13b71a39/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doc-pthread_getname_np.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20120224/13b71a39/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pthread-getname-test.c
Type: text/x-csrc
Size: 3511 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20120224/13b71a39/attachment-0002.bin>


More information about the Cygwin-patches mailing list