|
From: anton w. <ant...@ca...> - 2004-04-01 20:20:15
|
The program I'm writing needs a unique pid for each thread; therefore, it dies since valgrind uses user-level threading and getpid() always returns the same identifier. Is there any way around this? Thanks, Anton |
|
From: Michael P. <md...@tr...> - 2004-04-01 20:26:55
|
anton wilson writes: > The program I'm writing needs a unique pid for each thread; therefore, it dies > since valgrind uses user-level threading and getpid() always returns the same > identifier. Is there any way around this? The gettid() function returns a thread identifier. getpid() returning a different value for each thread was a behavior peculiar to certain versions of Linux; Linux 2.6 (and later) using recent glibc (one that includes NPTL) will exhibit the same behavior you see under valgrind. Michael Poole |
|
From: anton w. <ant...@ca...> - 2004-04-01 20:46:24
|
> The gettid() function returns a thread identifier. getpid() returning > a different value for each thread was a behavior peculiar to certain > versions of Linux; Does this mean that I can use gettid() with my version of linux (with the old glibc), and somehow have it compile and run correctly when using valgrind? Or do I really have to use linux 2.6 and a newer glibc to get the behavior i want at all? |
|
From: Michael P. <md...@tr...> - 2004-04-01 21:05:57
|
anton wilson writes: >> The gettid() function returns a thread identifier. getpid() returning >> a different value for each thread was a behavior peculiar to certain >> versions of Linux; > > > Does this mean that I can use gettid() with my version of linux > (with the old glibc), and somehow have it compile and run correctly > when using valgrind? Or do I really have to use linux 2.6 and a > newer glibc to get the behavior i want at all? Hm. As it turns out, gettid() is also Linux-specific; I should not have recommended it. It appears that the proper (portable) function to use is pthread_self() -- assuming you are using pthreads in the first place. This should work on any version of glibc since 2.0 (and for any other OS that implements POSIX threads). The POSIX spec apparently says that pthread_t must be an arithmetic type, but some implementations use a pointer instead (as permitted by an older version?). Michael |
|
From: Dirk M. <dm...@gm...> - 2004-04-01 20:59:38
|
On Thursday 01 April 2004 22:15, anton wilson wrote: > The program I'm writing needs a unique pid for each thread; therefore, it > dies since valgrind uses user-level threading and getpid() always returns > the same identifier. Is there any way around this? No, an application that uses getpid() for identifying a thread is broken. use gettid(). Dirk |
|
From: Nicholas N. <nj...@ca...> - 2004-04-02 08:50:08
|
On Thu, 1 Apr 2004, Dirk Mueller wrote: > > The program I'm writing needs a unique pid for each thread; therefore, it > > dies since valgrind uses user-level threading and getpid() always returns > > the same identifier. Is there any way around this? > > No, an application that uses getpid() for identifying a thread is broken. use > gettid(). I think Valgrind might not implement gettid() correctly, unfortunately; I think it gives the same value for all threads... N |