1

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

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

    /* 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.
         */

那么有没有人在原生安卓应用程序中使用过进程共享的互斥锁(和条件变量)(例如,通过与ashmem_create_region共享它们)?

4

2 回答 2

1

1、Android确实支持共享互斥量。2、Android 不支持健壮的互斥锁(robust futex),它可以“在进程因持有互斥锁而死亡时进行清理”。

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

于 2015-03-31T06:04:10.757 回答
0

我已经设法让它在 Android 5.0 上运行,所以它们是受支持的。其中一个进程创建共享内存并与另一个进程共享文件描述符,mmap 它并且它工作。

于 2015-03-14T08:04:42.400 回答