[Bug other/55070] New: pthread_getname_np returns the name with a terminating newline on Linux.
chandan.jc at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 25 01:30:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55070
Bug #: 55070
Summary: pthread_getname_np returns the name with a terminating
newline on Linux.
Classification: Unclassified
Product: gcc
Version: 4.5.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: chandan.jc@gmail.com
pthread_getname_np returns the name with a terminating newline.
Steps to reproduce:
Run the following program on Ubuntu 11.04 (should be reproducible on any
version).
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
void *threadfunc(void *parm)
{
printf("In the thread.\n");
sleep(20); // allow main program to set the thread name
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc=0;
char theName[16];
memset(theName, 0, sizeof(theName));
printf("Creating an unnamed thread\n");
rc = pthread_create(&thread, NULL, threadfunc, NULL);
if(0 == rc)
{
sleep(2);
rc = pthread_setname_np(thread, "THREADFOO");
sleep(2);
if(0 == rc)
{
rc = pthread_getname_np(thread, theName, 16);
if(0 == rc)
{
printf("The thread name is %s.\n", theName);
}
else
{
perror("pthread_getname_np");
}
}
else
{
perror("pthread_setname_np");
}
rc = pthread_join(thread, NULL);
}
if(0 != rc)
{
perror("pthread_create");
}
printf("Done\n");
return(rc);
}
Expected output:
Creating an unnamed thread
In the thread.
The thread name is THREADFOO.
Done
Actual Output:
Creating an unnamed thread
In the thread.
The thread name is THREADFOO
.
Done
As you can see, pthread_getname_np is adding a trailing newline to the returned
string.
More information about the Gcc-bugs
mailing list