问题 单项选择题

某书店有一个收银员,该书店最多允许n个购书者进入。将收银员和购书者看做不同的进程,其工作流程如图6-3所示。利用PV操作实现该过程,设置信号量S1、S2和Sn,初值分别为0,0,n。则图6-3中a1、a2、b1和b2应分别填入()。

A.P(S1)、V(S2)、P(S、V(S2)

B.P(S2)、V(、V(S、P(S2)

C.V(S1)、P(S2)、P(S1)、V(S2)

D.V(S、P(S、P(S2)、V(S1)

答案

参考答案:C

解析:

[要点解析] 这是一道考查利用P、V操作实现进程间的同步工作的综合分析题。对于本试题收银员进程和购书者进程之间是一个同步问题,需要设置两个同步信号量,即S1和S2。其中,信号量 S1表示购书者购书时,通知收银员进程做收费工作,初值为0。信号量S2表示收银员收费结束,通知购书者进程可以进行一步工作,初值为0。

由于该书店最多只允许有n个购书者进入,因此,书店是一个临界资源,最多允许n个购书者购书,对应的是设置一个互斥信号量Sn,初值等于n。当购书者进入书店时需要执行P(Sn)操作,用于查看书店是否有空闲位置允许其进入购书。若有空闲位置,则进入书店进行购书;若没有空闲位置,则进入等待状态。当购书者完成购书操作退出书店时,需要执行V(Sn)操作,表明书店中已有一个空闲位置,并唤醒其他进入等待状态的购书者进程。

购书者进程中,完成购书操作后先执行V(S1)操作表示购书结束,唤醒收银员进程做收费工作。然后执行P(S2),用于查看该购书者是否已缴费,若已缴费,则继续进行一步工作,即执行V(Sn);若未缴费,则进入等待状态。

对于收银员进程,先执行P(S1)操作,用于检查是否有准备缴费的购书者申请。若有,则进行执行下一步工作,即进行收费操作;若没有准备缴费的购书者申请,则进入等待状态。当完成收费任务后,需继续执行V(S2)操作,用于通知购书者进程可以进行一步工作。

由以上分析可知,(22)空缺处的正确答案为选项C。

问答题

Turkey’s Bodrum peninsula is different. The tourist boom in this part of the world (1) turned some small villages into resorts yet left neighbouring beaches undisturbed, making it quite (2) southern France or the Spanish Coasts where few stretches of coastline are undevelopeD.
The (3) for this happy set of circumstances is simple. For thousands of years, travel here (4) easier by boat than by lanD.So when mass tourism arrived in the (5) 1980s, there was no coast road for ribbon development to follow. So the peninsula, just (6) hour from Bodrum airport, has not become one long littoral of resort.
The building (7) new hotels has mainly been confined to places easily reached by then relatively (8) roads. Such ease of access has made Gumbet, near Bodrum, a busy resort, while the little fishing village of Gumusluk, 12 miles further west and only recently reachable by (9) , remains tranquil and undisturbeD.
It’s worth thinking carefully about location when planning a family (10) on the peninsulA.Choose a place that is centrally located, preferably out of earshot (11) Bodrum town’s "lively"—which means nosy—nightlife, and you can then use (12) area’s comfortably small scale to your advantage. Today’s new roads mean most places can (13) reached in under an hour by taxi or the ubiquitous dolmus-minibus.
The (14) of facilities at the Tamarisk Beach Hotel near the small village of Ortakent makes (15) a good base. The family-run hotel—rooms and suites are in two-storey buildings (16) by palm trees and flowers in terracotta pots—sits above its own sandy (17) beach, shaded by tamarisk trees and sheltered by nearby islands.
The hotel is (18) child-friendly, too. Children, from infants up to young teenagers, can take part in a (19) of games and activities that include tuition in windsurfing, dinghy (20) catamaran sailing.

判断题