Lect 07
Lect 07
Lecture 7: Semaphores
Instructor:Yongming Tang, Ph. D.
School of Computer Sciences and Engineering
Fairleigh Dickinson University
Semaphores
• Introduction
– A semaphore is a data structure that is shared
by several processes.
– Semaphores are most often used to synchronize
operations when multiple processes access a
common, non-shareable resource.
– Usually semaphores are used to avoid
starvation and deadlock.
printf("%d\t", intValue);
}
printf("\nI am process %d. I got five numbers ", getpid());
printf("from a producer as above.\n");
if (semctl(semID, 0, IPC_RMID, 0) == -1) {
perror(“semctl: IPC_RMID”);
exit(5);
}
}