Question: Programming in C, producer consumer, using semaphore Producer- consumer problem Write a program to synchronize processes with semaphores: a parent process fills a shared buffer

Programming in C, producer consumer, using semaphore

Programming in C, producer consumer, using semaphore Producer- consumer problem Write a

Producer- consumer problem Write a program to synchronize processes with semaphores: a parent process fills a shared buffer and sleeps for n seconds, and seconds. You will need the buffer, counter and semaphore, all stored in the shared memory (Hint: use a sem_t semaphore to your shared memory area. Initialize the semaphore with sem init. Perform the operation on the buffer and the counter in the critical section guarded by the sem wait and sem_post operations.) a child process prints the contents of the buffer and sleeps for m Experiment with the program by changing the (relative) production rate and the consumption rate (change sleep times n and m) to achieve a processes alternation. Explain the results Once you complete a task, please submit your solution via D2L. POSIX semaphore functions and types are defined in semaphore.h To define a semaphore object, use sem_t sem_name, To initialize a semaphore, use sem init(0 int seminit(sem_t *sem, int pshared, unsigned int value); .sem points to a semaphore object to initialize pshared is a flag indicating whether or not the semaphore should be shared with forkOed processes. LinuxThreads does not currently support shared semaphores value is an initial value to set the semaphore to Example of use: sem init(&sem name, 0, 10); To wait on a semaphore, use sem_wait: int sem_wait(semt sem) If the value of the semaphore is negative, the calling process blocks; one of the blocked processes wakes up when another process calls sem_post. Example of use: sem_wait(&sem_name); To increment the value of a semaphore, use sem_post: int sem_post(sem t *sem); It increments the value of the semaphore and wakes up a blocked process waiting on the semaphore, if any Example of use: sem post(&sem_name)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!