linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [urcu PATCH] test_urcu.c: use gettid()
@ 2009-02-06 18:49 Bert Wesarg
  2009-02-08  0:17 ` Mathieu Desnoyers
  0 siblings, 1 reply; 2+ messages in thread
From: Bert Wesarg @ 2009-02-06 18:49 UTC (permalink / raw)
  To: Mathieu Desnoyers, Mathieu Desnoyers; +Cc: linux-kernel, Bert Wesarg

It's probably better to print the tid for each thread, not the pid.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>

---
 test_urcu.c |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

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 <unistd.h>
 #include <stdio.h>
 #include <assert.h>
+#include <sys/syscall.h>
+
+#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)
-- 
tg: (24316d1..) bw/use-gettid (depends on: master)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [urcu PATCH] test_urcu.c: use gettid()
  2009-02-06 18:49 [urcu PATCH] test_urcu.c: use gettid() Bert Wesarg
@ 2009-02-08  0:17 ` Mathieu Desnoyers
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2009-02-08  0:17 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: linux-kernel

* Bert Wesarg (bert.wesarg@googlemail.com) wrote:
> It's probably better to print the tid for each thread, not the pid.
> 
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> 
Merged, thanks !

Mathieu

> ---
>  test_urcu.c |   28 ++++++++++++++++++++++++----
>  1 files changed, 24 insertions(+), 4 deletions(-)
> 
> 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 <unistd.h>
>  #include <stdio.h>
>  #include <assert.h>
> +#include <sys/syscall.h>
> +
> +#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)
> -- 
> tg: (24316d1..) bw/use-gettid (depends on: master)
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-08  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-06 18:49 [urcu PATCH] test_urcu.c: use gettid() Bert Wesarg
2009-02-08  0:17 ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).