Managing data for native threads at Android NDK
There are several options when we want to preserve thread-wide data across functions, including global variables, argument passing, and thread-specific data key. This recipe discusses all the three options with a focus on thread-specific data key.
Getting ready...
Readers are recommended to read the Creating and terminating native threads at Android NDK recipe and the Synchronizing native threads with mutex at Android NDK recipe in this chapter before this one.
How to do it...
The following steps will help us create an Android project that demonstrates data management at Android NDK:
Create an Android application named
NativeThreadsData
. Set the package name ascookbook.chapter6.nativethreadsdata
. Please refer to the Loading native libraries and registering native methods recipe in Chapter 2, Java Native Interface if you want more detailed instructions.Right-click on the project NativeThreadsData, select Android Tools | Add Native Support.
Add a...