Posts

Showing posts with the label Operating Systems

Producer Consumer- Operating Systems

In this project we are going to resolve the producer-consumer problem with limited buffer using threads. The produces produces an object and adds it to buffer while the customer consumes it, then removes it from the buffer. The problem arises in the fact that the producer and the consumer should not be allowed to access the shared buffer at the same time, as this will generate problems. Solving this problem can be implemented in different ways in this case will use pthreads. For this solution, we will need two traffic lights, counter for empty, full and a mutex lock. Producer and consumer will be executed as two independent threads. Buffer shall be a fixed-size array type buffer_item (defined using typedef). He will be manipulated as a circular row using two functions for adding and removing objects. Both thread will alternate between a time when they will manipulate the buffer and a time where they are in "sleep". As an output the program will have messages that appear whe...