Lab 5 - Synchronization Problems
๐๏ธ The wait, notify & notifyAll Methods
Let's assume we have 2 threads
๐๏ธ Semaphores
A semaphore can be seen as a lock that allows multiple threads to coexist in a certain critical region at any given time. The semaphore uses a counter that determines how many threads can still enter. Once at the semaphore, a thread is allowed to enter only if the number of threads in the critical region is less than the maximum number of threads set when creating the semaphore.
๐๏ธ Deadlock and Livelock
A deadlock occurs when threads are blocked, with each thread wanting to access resources held by another thread simultaneously. It can be exemplified as follows: there are two threads, T1 and T2. T1 holds lock P, and T2 holds lock Q. T1 wants to acquire lock Q, which is held by T2, and T2 wants to acquire lock P, held by T1.
๐๏ธ Classic Synchronization Problems
4 items
๐๏ธ Exercises
1. Starting from the code skeleton, in the oneProducerOneConsumer package, implement the Producer-Consumer algorithm for a buffer of size 1.