pthread function in testing print weird messages to stderr
This minimal program, test_threads.c:
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int thread_return;
void *
thread_function (void *arg)
{
int idx;
for ( idx = 0 ; idx < 3 ; idx++ ) {
sleep (1);
printf ("thread_arg: %d\n", *((int *)arg));
}
thread_return = 42;
pthread_exit (&thread_return);
}
int
main (void)
{
int thread_arg = 2;
pthread_t thread;
int return_code;
// pthread_attr_t thread_attrs;
// return_code = pthread_attr_init (&thread_attrs);
return_code = pthread_create (&thread, NULL, thread_function,
(void *) &thread_arg);
assert (return_code == 0);
int **return_location;
return_code = pthread_join (thread, (void **) return_location);
assert (return_code == 0);
printf ("thread_return: %d\n", **return_location);
return 0;
}
Compiled this way:
gcc -Wall -D_REENTRANT test_threads.c -lpthread -o test
without any errors or warnings, produces this output when run:
thread_arg: 2
thread_arg: 2
thread_arg: 2
thread_return: 42
1581:
1581: runtime linker statistics:
1581: final number of relocations: 139
1581: final number of relocations from cache: 7
with the latter four lines being on stderr. Is there some debugging
information that didn't get turned off or something? I guess this
might be a libc bug report?
Uncommenting the lines that set up the thread_attrs structure and
passing a pointer to it to pthread_create insteal of NULL as the
second argument yields a different weird output:
thread_arg: 2
thread_arg: 2
thread_arg: 2
thread_return: 42
1598: binding file /lib/tls/libpthread.so.0 to
/lib/tls/libc.so.6: normal symbol `__cxa_finalize' [GLIBC_2.1.3]
1598: binding file /lib/libgcc_s.so.1 to /lib/tls/libc.so.6:
normal symbol `__cxa_finalize' [GLIBC_2.1.3]
Any clues as to what is going on here would be greatly appreciated.
Thanks,
Britton
--
Britton Kerin
bkerin@fastmail.fm
Reply to: