Professional Documents
Culture Documents
Lab 6 Step 2
Lab 6 Step 2
// Date: 2023-08-01
// Title: Lab6 - Step 2
// Description: : This program recreates the producer-consumer problem where
// the alphabet is produced and consumed. It creates 2 threads, 1 for the producer
// and 1 for the consumer. It uses 3 semaphores to synchronize a buffer that is
// shared by the producer and consumer threads. One semaphore is used control
// filling the buffer, one is used to control emptying the buffer, and one is used
// as a mutex lock for the buffer. The threads will print out what character is
being
// produced or consumed. Once threads are finished with the alphabet, the main
thread exits.
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <assert.h>
#include <semaphore.h>
// Have the main thread wait for the producer/consumer threads to finish.
pthread_join(producer, NULL);
pthread_join(consumer, NULL);
return 0;
}