From: Bert Wesarg Date: Sat, 7 Feb 2009 23:59:29 +0000 (-0500) Subject: test_urcu.c: use gettid() X-Git-Tag: v0.1~320 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=87bd15cdb3e77c3d0a616c57ae3876ddea48a54f;p=userspace-rcu.git test_urcu.c: use gettid() It's probably better to print the tid for each thread, not the pid. Signed-off-by: Bert Wesarg --- diff --git a/test_urcu.c b/test_urcu.c index db0b68c..ea5a784 100644 --- a/test_urcu.c +++ b/test_urcu.c @@ -17,6 +17,23 @@ #include #include #include +#include + +#if defined(_syscall0) +_syscall0(pid_t, gettid) +#elif defined(__NR_gettid) +static inline pid_t gettid(void) +{ + return syscall(__NR_gettid); +} +#else +#warning "use pid as tid" +static inline pid_t gettid(void) +{ + return getpid(); +} +#endif + #include "urcu.h" struct test_array { @@ -36,8 +53,8 @@ void *thr_reader(void *arg) int qparity, i, j; struct test_array *local_ptr; - printf("thread %s, thread id : %lu, pid %lu\n", - "reader", pthread_self(), (unsigned long)getpid()); + printf("thread %s, thread id : %lx, tid %lu\n", + "reader", pthread_self(), (unsigned long)gettid()); sleep(2); urcu_register_thread(); @@ -66,8 +83,8 @@ void *thr_writer(void *arg) int i; struct test_array *new, *old; - printf("thread %s, thread id : %lu, pid %lu\n", - "writer", pthread_self(), (unsigned long)getpid()); + printf("thread %s, thread id : %lx, tid %lu\n", + "writer", pthread_self(), (unsigned long)gettid()); sleep(2); for (i = 0; i < 10000000; i++) { @@ -104,6 +121,9 @@ int main() void *tret; int i; + printf("thread %-6s, thread id : %lx, tid %lu\n", + "main", pthread_self(), (unsigned long)gettid()); + for (i = 0; i < NR_READ; i++) { err = pthread_create(&tid_reader[i], NULL, thr_reader, NULL); if (err != 0)