algorithm - Producer-consumer with sempahores -



algorithm - Producer-consumer with sempahores -

producer-consumer problem taken wikipedia:

semaphore mutex = 1 semaphore fillcount = 0 semaphore emptycount = buffer_size procedure producer() { while (true) { item = produceitem() down(emptycount) down(mutex) putitemintobuffer(item) up(mutex) up(fillcount) } up(fillcount) //the consumer may not finish before producer. } procedure consumer() { while (true) { down(fillcount) down(mutex) item = removeitemfrombuffer() up(mutex) up(emptycount) consumeitem(item) } }

my question - why producer have up(fillcount) //the consumer may not finish before producer after while loop. when programme there , why needed?

i think code doesn't create sense way. loop never ends, line in question can never reached.

the code didn't contain line, , added anonymous editor in march 2009. i removed line now.

in general, code on wikipedia edited many people on long period of time, it's quite easy introduce bugs it.

algorithm

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -