Cross-process Locking With Android Ndk?
Is there a way to lock e.g. using mutexes or file locks on Android NDK, across processes? I want to lock a socket so only one process can send to it at once. The processes are not
Solution 1:
Assuming the processes have the same user ID, you can use flock(2)
to lock a file (could be anything accessible to both processes), or the POSIX semaphore operations (sem_open(3)
) to use a semaphore.
If the user IDs are different, the mechanisms will still work, but you have to set the file permissions to be more "open" -- which introduces the risk of some malicious app performing a denial-of-service attack by grabbing the lock.
Post a Comment for "Cross-process Locking With Android Ndk?"