The code below is trying to insert a random value into a circular queue and remove it. However, there are some synchronization issues. I know I can use higher level routines
another problem in this code is that even if isEmpty/isFull return true - until you call the adjacent wait the state of the queue might change.
For example:
- queue is empty
- thread 1 calls isEmpty()
- context switch
- thread 2 calls enqueue (now the queue is not empty)
- context switch
- thread 1 not calls lock.wait() event though the queue is not empty
this problem of course will be solved when calls to wait()/notify() will be placed in a synchronized block.