Assignment 5 semaphore mechanisms


Rate this product

Assignment 5 (20 points)

As you have come to understand, the shmp1.cpp and shmc1.cpp you compiled and ran in Assignment 3 have serious deficiency due to race condition. In this assignment you are to correct the problem using the semaphore mechanisms that Linux provides. Note that any corrections you make should not include the removal or changes of the sleep() calls in the shmc1 program.
Two implementations of semaphore are commonly available on most distributions of UNIX and Linux operating systems. The System V implementation includes semget(), semctl(), and semop(), and a struct sembuf used in the semop() calls, which are defined in <sys/sem.h. The POSIX implementation includes sem_wait(), sem_post(), and sem_open(), sem_close() & sem_unlink() for named semaphore and sem_init() & sem_destroy() for unnamed semaphore, which are defined in

The program must run successfully on a Linux machine in the CECS Lab.

Do the following for this assignment:
1. Add necessary synchronization code in shmp1.cpp and shmc1.cpp to correct problems due to race condition, and compile them into executables shmp1 and shmc1, respectively.
2. Run your corrected version of shmp1 (with shmc1) to make sure that the output is correct.
3. Submit on BeachBoard the corrected shmp1.cpp and shmc1.cpp, with a cover page that provides your name, your student ID, course # and section, assignment #, due date, submission date, and a clear program description detailing what you have done for the correction. Format of the cover page should follow the cover page template on BeachBoard.
4. The programs must be properly formatted and adequately commented to enhance readability and understanding. Detailed documentation on system calls are especially needed.
5. Demonstrate your program on a Linux machine in the Lab and explain details of the program logic and execution results. Bring a hardcopy of the cover page for the demo.

Open chat
Need help?
Can we help you?