For some reason i am unable to compile or execute the following code ...look like a i have a deadlock or something like that ...
Could anyone send me into the right direction ? Thanks !!
This is the code:
Could anyone send me into the right direction ? Thanks !!
This is the code:
Code:
int itemCount
procedure producer() {
while (true) {
item = produceItem()
if (itemCount == BUFFER_SIZE) {
sleep()
}
putItemIntoBuffer(item)
itemCount = itemCount + 1
if (itemCount == 1) {
wakeup(consumer)
}
}
}
procedure consumer() {
while (true) {
if (itemCount == 0) {
sleep()
}
item = removeItemFromBuffer()
itemCount = itemCount - 1
if (itemCount == BUFFER_SIZE - 1) {
wakeup(producer)
}
consumeItem(item)
}
}
Comment