Android中的进程共享互斥锁和条件变量

Android中的进程共享互斥锁和条件变量

问题描述:

Android支持进程共享互斥锁和条件变量吗? 我听说仿生实现不支持它们,因为Android有IPC的其他方式,但找不到可以确认或否认它的信息。Android中的进程共享互斥锁和条件变量

来源有点混乱。在仿生的pthread_mutex.cpp之前 pthread_mutexattr_setpshared有一个评论:

/* process-shared mutexes are not supported at the moment */ 

但里面的功能有也被写入:

  /* our current implementation of pthread actually supports shared 
     * mutexes but won't cleanup if a process dies with the mutex held. 
     * Nevertheless, it's better than nothing. Shared mutexes are used 
     * by surfaceflinger and audioflinger. 
     */ 

所以已经有人使用进程共享的互斥体(和电导率vars)在原生android应用程序中(例如,通过与ashmem_create_region共享它们)?

我设法让它在Android 5.0上运行,所以它们得到了支持。 其中一个进程创建共享内存并与另一个进程共享文件描述符,这两个进程都是mmap而且它工作正常。

1,Android确实支持共享互斥。 2,Android不支持强大的互斥体(强大的futex),它可以“清理一个进程因持有互斥体而死亡”。

所以,只有系统进程可以使用它(永远不会崩溃或死亡,如果它崩溃,系统重新启动)。