进程间有共享内存,想要用读写锁来保护,可以吗?具体怎么使用呢?
应该可以。
把RWLock放到共享内存里就可以了。
pthread_rwlock_t * rwl;
rwl = (pthread_rwlock_t *)shmem_ptr;
shmem_ptr是什么意思?具体指什么?
shmem_t *shmem_ptr;
/* create the shared memory object */
fd = shm_open( argv[1], O_RDWR | O_CREAT, S_IRWXU );
/* set the size of the shared memory object */
ftruncate( fd, sizeof(shmem_t) );
/* get a pointer to a piece of the shared memory */
shmem_ptr = mmap( 0, sizeof(shmem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 );
......