Synchronizing native threads with reader/writer locks at Android NDK
The previous two recipes cover thread synchronization with mutex and conditional variables. This recipe discusses reader/writer locks in Android NDK.
Getting ready...
Readers are recommended to read the previous two recipes, Synchronizing native threads with mutex at Android NDK and Synchronizing native threads with conditional variables at Android NDK, before going through this one.
How to do it...
The following steps will help you create an Android project that demonstrates the usage of the pthread reader/writer lock:
Create an Android application named
NativeThreadsRWLock
. Set the package name ascookbook.chapter6.nativethreadsrwlock
. Refer to the Loading native libraries and registering native methods recipe in Chapter 2, Java Native Interface for more detailed instructions.Right-click on the project NativeThreadsRWLock, select Android Tools | Add Native Support.
Add a Java file named
MainActivity.java
under packagecookbook...