mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Q: uniqueness of pthread_t
@ 2014-03-24 10:40 Ulrich Windl
  2014-03-24 13:36 ` Mikael Pettersson
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Windl @ 2014-03-24 10:40 UTC (permalink / raw)
  To: linux-kernel

Hi!

I'm programming a little bit with pthreads in Linux. As I understand pthread_t is an opaque type (a pointer address?) that cannot be mapped to the kernel's TID easily. Anyway: Is it expected that when one thread terminates and another thread is created (in fact the same thread again), that the p_thread my be resused?

It seems it just happened when debugging my program (or I made a programming mistake (code compiles clean with -Wall):
---
[...]
cleanup_thread: 1 used connection entries
 5888 [^D] (null) -> 192.168.255.18/80
cleanup_thread: leaves with -1: No child processes
8407: [8413](172.20.64.67/54560) handles socket 4
cleanup_thread 139852035340032 terminated
created cleanup_thread 139852035340032
accepting connection (1 handlers)
[...]
---
libgthread-2_0-0-2.22.5-0.8.12.1 (SLES11 SP3 on x86_64)

The code handling the threads looks like this (so the results should be reliable, I guess):

                        if ( tid != 0 && pthread_tryjoin_np(tid, &ret) == 0 )
                        {
                                DEBUG(1) printf("cleanup_thread %ld terminated\\
n",
                                                (long) tid);
                                tid = 0;
                        }
[...]
                        if ( tid != 0 && pthread_tryjoin_np(tid, &ret) == 0 )
                        {
                                DEBUG(1) printf("cleanup_thread %ld terminated\\
n",
                                                (long) tid);
                                tid = 0;
                        }

(The code above also runs strictly sequential)

And while I'm at it: There's a bug in the man page:
---
PTHREAD_TRYJOIN_NP(3)      Linux Programmer's Manual     PTHREAD_TRYJOIN_NP(3)



NAME
       pthread_tryjoin_np,  pthread_timedjoin_np  -  try to join with a termi-
       nated thread

SYNOPSIS
       #define _GNU_SOURCE
       #include <pthread.h>

       int pthread_tryjoin_np(pthread_t thread, void **retval);

       int pthread_timedjoin_np(pthread_t thread, void **retval,
                                const struct timespec *abstime);

       Compile and link with -pthread.
---

You must include <features.h> after defining  _GNU_SOURCE, and you must do this early in your includes...

I'm not subscribed d to LKML, so please CC your answers to me.

Regards,
Ulrich



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

end of thread, other threads:[~2014-03-24 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 10:40 Q: uniqueness of pthread_t Ulrich Windl
2014-03-24 13:36 ` Mikael Pettersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®