pthread_cancel not found compiling with android to

2019-04-13 13:35发布

问题:

I'm compiling a program that is configured using the Android Toolchain. I'm using ndk r10c. I made a standalone toolchain using

$./make-standalone-toolchain.sh --ndk-dir=/home/justin/bin/android-ndk-r10c/ --install-dir=/home/justin/android-toolchain/

and was able to configure my project, but when I make I get

error: 'pthread_cancel' was not declared in this scope

The header has #include <pthread.h> and this answer seems to indicate that I should be able to use pthreads as I normally would.

Am I missing something?

回答1:

Bionic (Android's libc) does not have pthread_cancel. IIRC, when we discussed adding this we chose not to because implementation of it is error prone and harmful to performance (of all code).

As far as we could tell, no implementation of pthreads implements a fully correct pthread_cancel. It would also impose a cost on all code, even if you're not using pthread_cancel (because so many sections of code need to be guarded from interruption by pthread_cancel).