问题 单项选择题

理发店问题。有一个理发店,有m个理发师,店内配置了m个理发椅,分别与理发师一一对应;此外还配置了n个等待座席,供顾客在店内等候理发。一旦等候的顾客坐满等候座席,只能在门外排队等候进入理发店。试考虑最简单的方案,用P、V操作来实现能够保证顾客先来先进入理发店的秩序,需要()。

A.1个信号量,初值为m+n

B.2个信号量,初值分别为m,n

C.2个信号量,初值分别为m+n,0

D.3个信号量,初值分别为m,n,0

答案

参考答案:C

解析:

本题考查的是信号量的概念以及在解决同步、互斥问题中的应用。

由于理发店内只有n个等候席,m个理发椅,因此理发店内在同一时刻最多有m个顾客在理发的过程中,n个顾客在等候席上等待。一旦某个顾客理完发,离开座椅,等候席上等待的顾客可以顺序递补,开始理发。当想要理发的顾客人数太多时,等候席上也可能客满,这时顾客不能进入理发店,只能在店外排队等候。只有当一个顾客理完发离开理发椅,等候席上的第一个顾客坐上理发椅,空出了一个等候席,在门外排队等候的第一个顾客才可以进入并坐在等候席上等候理发。本题只有一个同步条件。这里,并不显式地指明顾客在店内的状态。

原则上,一个同步或互斥的条件将对应一个信号量,因此本题只设立一个信号量S,它的初值为m+n。

这里,能进入理发店的顾客可以达到m+n个,其中,前面m个顾客坐上了理发椅理发,后面n个顾客在等候席上等候。多于m+m个的顾客进入信号量S对应的等待队列中等待,其语义是在理发店门外排队等候。一旦某个顾客理完发并离开理发店,将请门外的第一个顾客进入。

当然,这里可以保证顾客先来先进入理发店,但不保证先来的顾客先离开理发店。这也是很自然的,符合实际情况。但是,这种方法却不能保证店内的秩序。

顾客流程:

P(S)→进入理发店,在等候席上等待,理发→V(S)

判断题
单项选择题

If you think you can make the planet better by clever shopping, think again. You might make it worse.

You probably go shopping several times a month, providing yourself with lots of opportunities to express your opinions. If you are worried about the environment, you might buy organic food; if you want to help poor farmers, you can do your bit by buying Fairtrade products; or you can express a dislike of evil multinational companies and rampant globalization by buying only local produce. And the best bit is that shopping, unlike voting, is fun; so you can do good and enjoy yourself at the same time.

Sadly, it’s not that easy. (41) . People who want to make the world a better place cannot do so by shifting their shopping habits: transforming the planet requires duller disciplines, like politics.

Organic food, which is grown without man-made pesticides and fertilisers, is generally assumed to be more environmentally friendly than conventional intensive farming, which is heavily reliant on chemical inputs. But it all depends on what you mean by "environmentally friendly". Farming is inherently bad for the environment: since humans took it up around 11 000 years ago, the result has been deforestation on a massive scale.

(42) . Organic methods, which rely on crop rotation, manure and compost in place of fertiliser, are far less intensive. So producing the world’s current agricultural output organically would require several times as much land as is currently cultivated. There wouldn’t be much room left for the rainforest.

Fairtrade food is designed to raise poor farmers’ incomes. It is sold at a higher price than ordinary food, with a subsidy passed back to the farmer. But prices of agricultural commodities are low because of overproduction, (43) .

Surely the case for local food, produced as close as possible to the consumer in order to minimise "food miles" and, by extension, carbon emissions, is clear Surprisingly, it is not. A study of Britain’s food system found that nearly half of food-vehicle miles (i. e. , miles travelled by vehicles carrying food) were driven by cars going to and from the shops. Most people live closer to a supermarket than a farmer’s market, so more local food could mean more food-vehicle miles. Moving food around in big, carefully packed lorries, as supermarkets do, may in fact be the most efficient way to transport the stuff

What’s more, once the energy used in production as well as transport is taken into account, local food may turn out to be even less green. (44) . And the local-food movement’s aims, of course, contradict those of the Fairtrade movement, by discouraging rich-country consumers from buying poor-country produce. But since the local-food movement looks suspiciously like old-fashioned protectionism masquerading as concern for the environment, helping poor countries is presumably not the point.

(45) . The problems lie in the means, not the ends. The best thing about the spread of the ethical-food movement is that it offers grounds for hope. It sends a signal that there is an enormous appetite for change and widespread frustration that governments are not doing enough to preserve the environment, reform world trade or encourage development.

42()

A.The aims of much of the ethical-food movement--to protect the environment, to encourage development and to redress the distortions in global trade--are admirable.

B.By maintaining the price, the Fairtrade system encourages farmers to produce more of these commodities rather than diversifying into other crops and so depresses prices--thus achieving, for most farmers, exactly the opposite of what the initiative is intended to do.

C.Proper free trade would be by far the best way to help,poor farmers. Taxing carbon would price the cost of emissions into the price of goods, and retailers would then have an incentive to source locally if it saved energy.

D.There are good reasons to doubt the claims made about three of the most popular varieties of "ethical" food: organic food, Fairtrade food and local food.

E.But following the "green revolution" of the 1960s greater use of chemical fertiliser has tripled grain yields with very little increase in the area of land under cultivation.

F.And since only a small fraction of the mark-up on Fairtrade foods actually goes to the farmer--most goes to the retailer-the system gives rich consumers an inflated impression of their largesse and makes alleviating poverty seem too easy.

G.Producing lamb in New Zealand and shipping it to Britain uses less energy than producing British lamb, because fanning in New Zealand is less energy-intensive.