问题 多项选择题

有一个仓库,可以存放A和B两种产品,但要求:
(1)每次只能存入一种产品(A或B);
(2)-N<A产品数量-B产品数量<M。
其中,N和M是正整数。试用P、V操作描述产品A与B的入库过程。

答案

参考答案:semaphore mutex=A, Sa=M-A, Sb=N-A;
main()
{
Cobegin
A产品入库进程
{i=0;
while (A)
{
P(Sa);
P(mutex);
A产品入库
V(mutex);
V(sb);
}
}
B产品入库进程
{j=0;
while(A)
{
P(sb);
P(mutex);
B产品入库
V(mutex);
V(Sa);
}
}
Coend
}

解析: 本问题存在以下同步和互斥关系:(1)两个产品入库进程不能同时入库,每次只能存入一种产品,因此,仓库的入口是一个临界资源,两种产品的入库进程之间需要互斥。设互斥信号量mutex,初值为1。
(2)两种产品的数量需满足的关系式-N<A产品数量-B产品数量<M,要求两个产品入库进程之间需要同步:A产品数量-B产品数量<M,当A产品数量-B产品数量>=M时A产品入库进程序等待,当B产品数量-A产品数量>=N时B产品入库进程序等待,因此,设两个信号量Sa、Sb,Sa表示目前仓库中可再存放的A产品的数量,Sb表示目前仓库中可再存放的B产品的数量,初始状态下A和B产品数均为0,因此,可存放A产品的最大数量为M-1,可存放B产品的最大数量为N-1,所以初值分别为M-1、N-1。

多项选择题
完形填空
My 9-year-old daughterAnd I were flying from our home in Carolina to spendA week with my husband in Florida.We were__About the trip because we hadn't seen him for five months,And __  her Dad terribly.
As usual on the Charlotte-to-Miami flight, the plane was totally__ . Because we did not get our boarding passes until we__ At the gate, KallieAnd I could not get seats togetherAnd were __  by theAisle(过道). IAsked two passengers in my row if they would switch places with KallieAnd me, __  we could be together. They __  , saying they thought they should stay in theirAssigned seats.
Meanwhile,A motherAnd her three children were inA _   several rowsAhead of us. There had beenA mistake in their boarding passes,And _  the whole family had been split up. The passengers in her row_   refused to move elsewhere. She was very__ About the younger boy sitting with strangers. She was in tears, yet nobody__   to help her.
There wereA troop of Boy Scouts(童子军) on __  . Suddenly the Scout leader stood upAnd said, "Ma’am, I think we can help you." He then __   five minutes rearranging his group so thatAdequate space was __   for the family. The boys followed his directions cheerfullyAnd without _  ,And the mother's relief was obvious.
Kallie, however, was beginning to panicAt the _   not being next to me. I told her that there wasn’tAnything I could do. __  , the man sitting next to the Scoutmaster, __   to meAndAsked, "Would youAnd your daughter like our seats?" __   to himselfAnd the Scoutmaster. We traded seatsAnd continued our trip, very much relieved to be togetherAnd watch the scenery from Kallie’s window seat.
小题1:
A.worriedB.excitedC.anxiousD.eager
小题2:
A.lovedB.consideredC.imaginedD.missed
小题3:
A.fullB.crowdedC.emptyD.overweight
小题4:
A.reachedB.arrivedC.landedD.knocked
小题5:
A.dividedB.blockedC.separatedD.connected
小题6:
A.in caseB.even ifC.as ifD.so that
小题7:
A.preventedB.refusedC.agreedD.promised
小题8:
A.panicB.hurryC.rushD.seat
小题9:
A.howeverB.otherwiseC.thereforeD.instead
小题10:
A.tooB.evenC.everD.also
小题11:
A.concernedB.curiousC.particularD.content
小题12:
A.suggestedB.offeredC.providedD.supplied
小题13:
A.dutyB.watchC.boardD.spot
小题14:
A.tookB.costC.paidD.spent
小题15:
A.convenientB.availableC.probableD.comfortable
小题16:
A.permissionB.excuseC.apologyD.complaint
小题17:
A.thoughtB.endC.feelingD.sense
小题18:
A.ImmediatelyB.PuzzlinglyC.ClearlyD.Amazingly
小题19:
A.turned upB.turnedAroundC.turned outD.turnedAway
小题20:
A.stickingB.keepingC.wavingD.referring