You may choose one of them to work on.
Please Find the attachments. Output should be in the same way as in scanned copies attached. Also attached Basic structure for both the programs.
(1) Write a program in C++ to implement the bounded-buffer problem shown in class. The circular buffer pool has 10 buffers (0..9) in it which are accessed concurrently by 2 producers and 1 consumer. You should use 2 condition variables and two critical sections for the 2 types of threads. You should also implement the functions put() and get() shown in class for the producers and consumer, respectively. The items produced by the producer threads should be generated using a random number generator. You should also delay the two producers and the consumer by 1 second, 3 seconds, and 2 seconds, respectively, each time an item is deposited into or retrieved from the buffer pool. Refer to the handout distributed in class to get an idea of what need be generated from your program.
(2) Write a program in C++ to synchronize two threads that both can increment “counter” concurrently. You should implement the functions sem_init(), sem_wait(), and sem_post() shown in Fig. 31.12 using a condition variable. The two threads are synchronized using sem_wait() and sem_post to increment “counter”. Refer to the handout distributed in class to get an idea of what need be generated from your program.
Use the following criteria to prepare and turn your programs in.
Submit ONLY your source code file(.cpp)
Hi,
I am a graduate in CS and working as a C++ programmer for 4+ years.
I have done lots of assignments both in academic courses and in freelancer.com implementing circular buffer for generic types. Also I implemented producer/consumer, reader/writer and dining philosopher problem for multithread.
I assure you of clean, efficient code with proper comment and documentation.
thanks