I am going to make an android game engine, primary using native C++. I want to use threading and I don't want to implement it in Java, because of the JNI's slowness. Are there any stable native threading APIs for Android, I could use?
Asked
Active
Viewed 2,502 times
3 Answers
6
I did some research on the topic (threading support in Android NDK) today, and it seems the options are as follows:
C++11 has native threading support on Android
Posix Threads (aka pthread).
Boost is available on Android, and includes threading support.
Poco is available on Android, and includes threading support.

iammilind
- 68,093
- 33
- 169
- 336

Jasper Blues
- 28,258
- 22
- 102
- 185
1
Try using pthreads
in libpthread

Zach Saucier
- 24,871
- 12
- 85
- 147

justin
- 104,054
- 14
- 179
- 226
-
They don't mention libpthread here: http://developer.android.com/sdk/ndk/overview.html. Is it part of the libc library? – Martin Erhardt Apr 20 '12 at 19:12
-
@MartinErhardt it appears to be part of libc/bionic (<< not an android dev). just `#include
`. – justin Apr 20 '12 at 19:21 -
thank you for support I just found a great tutorial on this topic:http://android.wooyd.org/JNIExample/files/JNIExample.pdf – Martin Erhardt Apr 20 '12 at 19:30
-
1Also check out the docs/STABLE-APIS.html file in NDK. It says "Note that the Android C library includes support for pthread (
), so "LOCAL_LIBS := -lpthread" is not needed. The same is true for real-time extensions (-lrt on typical Linux distributions)." – Mārtiņš Možeiko Apr 20 '12 at 19:59
0
You can also try the threads (Boost.Thread) of Boost for Android.
I don't want to implement it in Java, because of the JNI's slowness
According to the first post here, going native is not always going to make your code run faster (you may be still calling Java code from your C++ under the hood).
-
1. Where shall I know from that the Boost library also contain Threading APIs, if I am not aware of Desktop C++ libraries(no reason for downvoting) 2. Did I say going native makes your code run always faster? - I am just afraid of calling a C function from Java each time the Java-Thread loops through(even if I may be still calling Java code from your C++ under the hood) – Martin Erhardt Apr 22 '12 at 14:13
-
I didn't understand your comment 1. -- I was just proposing the Boost threads, didn't mean to insult you or anything. The only definitive answer to performance problems is to profile your program, so that you know what really takes time. Maybe you can run a small test with JNI and with C++, this will show you what's best for your needs. – gfour Apr 22 '12 at 21:24
-
Also not sure why the down-vote. . . 1. Boost or Poco are both options. 2. The stated reason for not using Java is because of JNI slowness, and you did address this fairly in your answer. – Jasper Blues Nov 26 '12 at 12:23