Po pierwsze, aby zdecydować, które toolchain w obsłudze, edycji "application.mk" (nie mylić z android.mk) i wstawić do gcc 4.8:
NDK_TOOLCHAIN_VERSION := 4.8
lub jeśli chcesz szczęk:
NDK_TOOLCHAIN_VERSION := clang
Ale to nie ma nic wspólnego z wątkami. To tylko określi, który zestaw narzędzi do użycia.
Teraz o wątkach, oto prosty przykład dla 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)
}
Zobacz np. http://stackoverflow.com/questions/15269496/how-to-compile-c11-code-with-android-ndk-and-eclipse i http: // stackoverflow.com/questions/14014659/android-ndk-error-musi-być-włączony-z-std-c11-lub-std-gnu11-kompilator – Michael
@ Michael, muszę zbudować z clang 3.2 lub gcc 4.8 lub być upewnij się, że nie jest to możliwe i użyj pthreads. – Kimi
Od wersji NDK 10d - GCC 4.8 jest domyślnie dla wszystkich 32-bitowych ABI –