|
Boost : |
Subject: Re: [boost] [Interprocess::Semaphore] Deadlock on more producers - one consumer problem
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-06-18 10:50:40
Cosimo Calabrese wrote:
> Is there a way to unlock all the producers with the
> boost::interprocess::semaphore? Or I have mistaken the approach of the
> problem?
If a semaphore count represents free resources, shouldn't post be
performed by the producer to signal available resources? You can try this:
http://en.wikipedia.org/wiki/Producer-consumer_problem#Using_semaphores
semaphore fillCount = 0
semaphore emptyCount = BUFFER_SIZE
procedure producer() {
while (true) {
item = produceItem()
down(emptyCount)
putItemIntoBuffer(item)
up(fillCount)
}
}
procedure consumer() {
while (true) {
down(fillCount)
item = removeItemFromBuffer()
up(emptyCount)
consumeItem(item)
}
}
where down is "wait" and up is "post".
Best,
Ion
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk