简体   繁体   English

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

[英]Process-shared mutexes and conditional variables in Android

Does Android support process-shared mutexes and condition variables? Android是否支持进程共享的互斥锁和条件变量? I've heard bionic implementation doesn't support them because Android has other means of IPC, but cannot find information that would either confirm or deny it. 我听说仿生实施不支持它们,因为Android具有IPC的其他方式,但是找不到能够确认或拒绝它的信息。

The sources are a bit confusing. 消息来源有些混乱。 In bionic's pthread_mutex.cpp just before pthread_mutexattr_setpshared there is a comment: 在仿生的pthread_mutexattr_setpshared之前的pthread_mutex.cpp中,有一个注释:

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

But inside the function there is also written: 但是在函数内部也写着:

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

So has anybody used process-shared mutexes (and cond vars) in native android applications (by sharing them with ashmem_create_region , for example)? 那么,有人在本地android应用程序中使用过进程共享的互斥对象(和cond vars)吗(例如,通过与ashmem_create_region共享它们)?

1, Android does support the shared mutex. 1,Android确实支持共享互斥。 2, Android does not support robust mutex(robust futex) which can "cleanup if a process dies with the mutex held". 如图2所示,Android不支持健壮的互斥锁(robust futex),后者可以“如果进程死于持有的互斥锁,则进行清理”。

So, only the system process can use it (never crash or killed, if it crash, the system reboot). 因此,只有系统进程才能使用它(永远不会崩溃或杀死,如果崩溃,则系统将重新启动)。

I've managed to get it working on Android 5.0, so they are supported. 我设法使它在Android 5.0上运行,因此受支持。 One of the processes creates shared memory and shares file descriptor with the other one, both mmap it and it works. 其中一个进程创建共享内存并与另一个进程共享文件描述符,二者都映射它并起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM