In primo luogo, decidere quale toolchain da utilizzare, modificare il "application.mk" (da non confondere con android.mk) e inserire per gcc 4.8:
NDK_TOOLCHAIN_VERSION := 4.8
o se si desidera clang:
NDK_TOOLCHAIN_VERSION := clang
Ma questo non ha nulla a che fare con i thread. Questo definirà solo quale toolchain usare.
Ora circa le discussioni, ecco un semplice esempio per Android NDK:
#include <pthread.h> // <--- IMPORTANT
// This will be used to pass some data to the new thread, modify as required
struct thread_data_arguments
{
int value_a
bool value_b;
};
//---------------------------------
// This function will be executed in the new thread, do not forget to put * at the start of the function name declaration
void *functionRunningInSeparateThread(void *arguments)
{
struct thread_data_arguments *some_thread_arguments = (struct thread_data_arguments*)arguments;
if (some_thread_arguments->value_b == true)
{
printf("VALUE= %i", some_thread_arguments->value_a);
}
// Signal the end of the thread execution
pthread_exit(0);
}
//---------------------------------
// This is the actual function creating and starting the new thread
void startThread()
{
// Lets pass some data to the new thread, you can pass anything even large data,
// for that you only need to modify thread_data_arguments as required
struct thread_data_arguments *some_thread_arguments;
some_thread_arguments = (thread_data_arguments*)malloc(sizeof(*some_thread_arguments));
some_thread_arguments->value_a = 12345;
some_thread_arguments->value_b = true;
// Create and start the new thread
pthread_create(&native_thread, NULL, functionRunningInSeparateThread, (void*)some_thread_arguments)
}
Vedere ad es. http://stackoverflow.com/questions/15269496/how-to-compile-c11-code-with-android-ndk-and-eclipse e http: // StackOverflow.it/questions/14014659/android-ndk-error-deve-essere-abilitato-con-lo-std-c11-o-std-gnu11-compiler – Michael
@ Michael, ho bisogno di compilare con clang 3.2 o gcc 4.8, o essere certo che non è possibile e usare pthreads. – Kimi
Dalla revisione 10d NDK - GCC 4.8 è l'impostazione predefinita per tutti gli ABI a 32 bit –