共享内存相关的函数shm_open、shm_unlink。Linux系统中可用,Android系统上不支持。
函数shm_open的作用是打开一个特殊的文件,返回file descriptor,这个fd可以与mmap一同使用。
http://comments.gmane.org/gmane.comp.gnu.apl.bugs/1377
Elias Mårtenson | 2 Jun 10:53 2014
Android codecompatibility issues
I've compiled GNU APL for Android, and I'm about to start working on theuser interface. Building it was remarkably simple, but it exposed two smallissues that required some code changes:
First of all, SystemVariable.cc includes "langinfo.h". This fileis not available on Android, but simply commenting this one out fixed theissue. Is it even needed anywhere else? Can it be completely removed? If not,can it be placed inside some #ifdef?
The second issue is that the SHM calls don't exist on Android. I solved itby creating versions of shm_open() and shm_unlink() that simply returns -1 (andsets errno to ENOSYS). This makes the code compile, but it's pretty ugly. Wouldit make sense to provide a configure option to disable the use of sharedmemory? (and, by extension, the AP's)
Regards,
Elias
Juergen Sauermann | 2 Jun 16:41 2014
Re: Android code compatibility issues
Hi Elias,
I have removed langinfo.h (a left-over from internationalization which I
removed earlier, SVN 307.
shm_open() and shm_unlink will go away long-term because I will move the
shared memory database to a
separate thread. Just didn't have enough time yet to do that.
/// Jürgen
在Linux系统中,sem_open执行后,在maps文件中能看到系统创建了共享内存。
在Android系统中,sem_open不支持。根据ndk的文档,sysv ipc不支持的。
http://www.cnblogs.com/crazii/p/3478465.html
[原]android不支持命名的semaphore
之前sem_open在iOS上, 创建命名的semaphore没有问题 (iOS不支持匿名的semaphore), 但是现在Android平台的sem_open时候报错,返回ENOSYS.
命名的semaphore因为有名字,可以在不同进程间访问,
幸好我这里不需要进程间共享和通信, 直接使用匿名semaphore也可以. (貌似匿名的semaphore也可以通过mmap实现进程共享和通信.但目前没有需求).
使用sem_init 和sem_destroy代替sem_open和sem_close, 问题解决.