objectConditionDemo{ defmain(args: Array[String]): Unit = { val queue = newBoundedBuffer for (i <- 1 to 10) { newThread { overridedefrun(): Unit = { queue.put(s"Item$i") } }.start() } for (i <- 1 to 10) { newThread { overridedefrun(): Unit = { queue.take } }.start() } }
classBoundedBuffer{ finalval lock = newReentrantLock finalval notFull = lock.newCondition finalval notEmpty = lock.newCondition finalval items = newArray[Any](3) var putptr = 0 var takeptr = 0 var count = 0
put Item8 put Item10 put Item5 take Item8 put Item7 take Item10 put Item9 take Item5 put Item1 take Item7 put Item4 take Item9 put Item2 take Item1 put Item6 take Item4 put Item3 take Item2 take Item6 take Item3