In process-1
I am trying to write the data into shared memory. At the same time in process-2
I am reading the data from the same shared memory. in this case I need to provide synchronization between these two processes. if I will go through unnamed semaphores (using shm_init(),mmap()
),will it work or not?
I have written code like this will it work or not?
fd = shm_open("shm_name", O_CREAT| O_RDWR, S_IRUSR | S_IWUSR);
sema = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE,MAP_SHARED , fd, 0);
sem_init(sema, 1, 1);