l*****c 发帖数: 1153 | 1 今天下午没事编出来个题,呵呵。
Implement a multi-consumer multi-producer model such that:
1. each consumer could consume multiple resources at a time, which means each
consumer must get a given number of resource at once. The interface of the
consumer would look like: void consumer(int n) where n is the number of resource it
needs at once.
2. each producer produces multiple resources, similar like the consumer.
3. The consumers are served on a less-demond-first-serve basis, such that at
each time the consumer |
f*******y 发帖数: 988 | 2 这个题目貌似不太适合interview
看起来没个把个小时搞不出
each
it
at
requires
【在 l*****c 的大作中提到】 : 今天下午没事编出来个题,呵呵。 : Implement a multi-consumer multi-producer model such that: : 1. each consumer could consume multiple resources at a time, which means each : consumer must get a given number of resource at once. The interface of the : consumer would look like: void consumer(int n) where n is the number of resource it : needs at once. : 2. each producer produces multiple resources, similar like the consumer. : 3. The consumers are served on a less-demond-first-serve basis, such that at : each time the consumer
|
l*****c 发帖数: 1153 | 3 我是说这个如果可以搞定,那么interview的题应该不在话下了。
【在 f*******y 的大作中提到】 : 这个题目貌似不太适合interview : 看起来没个把个小时搞不出 : : each : it : at : requires
|
p***o 发帖数: 1252 | 4 Nice problem. I need as many semaphores as consumers and one lock.
Is there any better solution?
To prove the correctness is also interesting.
each
resource it
at
requires
【在 l*****c 的大作中提到】 : 今天下午没事编出来个题,呵呵。 : Implement a multi-consumer multi-producer model such that: : 1. each consumer could consume multiple resources at a time, which means each : consumer must get a given number of resource at once. The interface of the : consumer would look like: void consumer(int n) where n is the number of resource it : needs at once. : 2. each producer produces multiple resources, similar like the consumer. : 3. The consumers are served on a less-demond-first-serve basis, such that at : each time the consumer
|
l*****c 发帖数: 1153 | 5 The problem is, you don't know how many consumers are there. Actually the
number of consumers might be dynamically changing during the processing.
【在 p***o 的大作中提到】 : Nice problem. I need as many semaphores as consumers and one lock. : Is there any better solution? : To prove the correctness is also interesting. : : each : resource it : at : requires
|
p***o 发帖数: 1252 | 6 That's what I mean ... You create one when entering Consumer( ) and destroy
it when leaving Consumer( ).
【在 l*****c 的大作中提到】 : The problem is, you don't know how many consumers are there. Actually the : number of consumers might be dynamically changing during the processing.
|
l*****c 发帖数: 1153 | 7 OK. I know what you mean. That works. Where is your complete solution? But I
think we only need one semaphore to count the # of consumers, no need to be
one semaphore per consumer.
I have a solution with three semaphores (but I left it at home).
destroy
【在 p***o 的大作中提到】 : That's what I mean ... You create one when entering Consumer( ) and destroy : it when leaving Consumer( ).
|