How to get current thread id in android ndk?

8,689 views
Skip to first unread message

Riasat Abir

unread,
Mar 18, 2011, 3:16:32 AM3/18/11
to android-ndk, David Turner, al...@birtles.org.uk
Hi,

How can I get the current thread id in android ndk?

This is used for linux: pid_t tid = syscall(SYS_gettid);

will it be serve the same purpose for android: pid_t  gettid(void); //defined in unistd.h 

Thanks,
Riasat

Giang Pham

unread,
Mar 18, 2011, 3:34:13 AM3/18/11
to andro...@googlegroups.com

I used to test a sample C++, and get thread id by the function pthread_self(). Its from C++, then I port to Java using NDK.

 

It returned the id, although I didn’t check if it was right or wrong, J. U should try that?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

alan

unread,
Mar 18, 2011, 5:37:08 AM3/18/11
to andro...@googlegroups.com
please don't send emails directly to david and myself. If either of us are able to answer your question we will answer it here.

Riasat Abir

unread,
Mar 18, 2011, 6:16:10 AM3/18/11
to andro...@googlegroups.com
okk sorry :(

On Fri, Mar 18, 2011 at 3:37 PM, alan <al...@birtles.org.uk> wrote:
please don't send emails directly to david and myself. If either of us are able to answer your question we will answer it here.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.



--

HimHim

David Turner

unread,
Mar 18, 2011, 6:49:57 AM3/18/11
to andro...@googlegroups.com, Riasat Abir, al...@birtles.org.uk
gettid() is defined in <unistd.h> in Bionic.

The function isn't defined in GLibc for some odd reason.

pthread_self() will not return the kernel thread id, but something else corresponding to the pthread implementation.
They should not be confused.

--
Reply all
Reply to author
Forward
0 new messages