avatar
给大家出个多进程的题# Programming - 葵花宝典
l*c
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
avatar
f*y
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

avatar
l*c
3
我是说这个如果可以搞定,那么interview的题应该不在话下了。

【在 f*******y 的大作中提到】
: 这个题目貌似不太适合interview
: 看起来没个把个小时搞不出
:
: each
: it
: at
: requires

avatar
p*o
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

avatar
l*c
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

avatar
p*o
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.

avatar
l*c
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( ).

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。