Synchronization Semaphor


  • To achieve synchronization between several processes, we need to register shared memory with operating system. That requires operating system's help. In this project, we use system call "Regshm ((char *) &shm, sizeof (shm));"
  • mykernel3.c contains codes in kernel space. Functions defined in it are system calls, such as MySeminit(), MyWait(), MySignal(), and so on. Every process calls these system calls will execute the same piece of codes, and share the same static and heap section, but with their own stack section.
  • When MySeminit(p, v) is called, we go to kernel space and execute codes in mykernel3.c. It will select a free semaphor in the semphor table in kernel space, initialize its value to v, and return the index to the semaphor.
  • The user program use the shared memory to store the index of semaphor. "shm.mutex = Seminit(1);" The indexes of semaphors are not necessarily shared memory, but can also be achieved by using global variable, because they remain constant in this program. However, and shm.nextvalid must be shared memory.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License