第三章 作业参考答案
结构力学 第三章 作业参考答案

B
M图(kN m)
(1) (2)
解: (1)求支座反力
∑M = 0 ∑F = 0
A y
取左边或者右边为隔离体,可得:
∑M ∑F
x
C
=0
⇒ FBx =
M h
(3) (4)
=0
最后容易做出结构的弯矩图。
3—18 试作图示刚架的 M 图。
C 0.8kN/m 0.5kN/m D E
14.625 4.225 12.8375
3—19 试作图示刚架的 M 图。
20kN
24 16
C
24
16
B FAx A FBy FAy
FBx
1m
2m
2m
2m
M图(kN m)
(1) (2) (3)
解:对整体:
∑M ∑F
y
A
=0
FBy × 4 + FBx ×1 = 20 × 2 FAy + FBy = 20 FAx − FBx = 0 FBx × 2 − FBy × 2 = 0
40kN m
10kN m M图(kN m)
32.5kN
20kN
20kN F(kN) S
解:求支座反力。取整体:
47.5kN
∑M ∑F
A
=0
FB × 8 − 20 ×10 − 10 ×10 × 3 − 40 = 0 FAy + FB − 10 ×10 − 20 = 0
然后即可做出弯矩图,利用弯矩图即可作出剪力图。
然后即可做出整个刚架的弯矩图。结点受力校核如下图。
D
qL 4 qL 2 qL 2
qL 4
qL 4
E
qL 2 qL 2
第3章作业参考答案

λ2l
l!
e− λ2 ,
l = 0,1,2,"
P( X + Y = n) = ∑ P{ X = k}P{Y = n − k}
k =0
=∑
k =0
n
λ1
k
k!
e −λ1
λ2
n−k
(n − k )!
e −λ2 =
e −( λ1+λ2 ) n λ1 λ2 e −( λ1+λ2 ) n k k n−k e −( λ1+λ2 ) n ! = ∑ ∑ Cn λ1 λ2 = n! (λ1 + λ2 )n n! k =0 k! (n − k )! n! k =0
18. 设随机变量 X 和 Y 的联合概率密度为
λ1k
e
−λ1
λ2n−k
e−λ2
⎛ λ2 ⎞ ⎜ ⎜λ +λ ⎟ ⎟ ⎝ 1 2⎠
n−k
f ( x, y ) =
1 − 2 (x2 + y2 ) e , ( x, y ) ∈ R 2 2π
1
计算概率 P{− 2 < X + Y < 2 2} 。 解:
19. 随机变量 X 与 Y 相互独立,X 服从参数为 λ 的指数分布,Y~U(0, h), 求 X+Y 的概率密 度。 解:
20. 一射手向某个靶子射击,设靶心为坐标原点,弹着点坐标(X,Y)服从二维正态分布 N(0,1;0,1;0). 求弹着点与靶心的距离 Z 的概率密度函数。 解: (X,Y)的联合概率密度为
f ( x, y ) =
1 − 2(x2 + y2 ) e , ( x, y ) ∈ R 2 2π
1
弹着点与靶心的距离 Z 的分布函数为
(完整版)第三章作业和参考答案解析

1. 什么是烃类热裂解?答:烃类的热裂解是将石油系烃类燃料(天然气、炼厂气、轻油、柴油、重油等)经高温作用,使烃类分子发生碳链断裂或脱氢反应,生成相对分子质量较小的烯烃、烷烃和其他相对分子质量不同的轻质和重质烃类。
2.烃类热裂解制乙烯可以分为哪两大部分?答:烃类热裂制乙烯的生产工艺可以分为原料烃的热裂解、裂解产物的分离两部分。
3. 在烃类热裂解系统内,什么是一次反应?什么是二次反应?答:一次反应是指原料烃裂解(脱氢和断链),生成目的产物乙烯、丙烯等低级烯烃的反应,是应促使其充分进行的反应;二次反应则是指一次反应产物(乙烯、丙烯等)继续发生的后续反应,生成分子量较大的液体产物以至结焦生炭的反应,是尽可能抑制其进行的反应。
4. 用来评价裂解燃料性质的4个指标是什么?答:评价裂解燃料性质的4个指标如下:(1)族组成—PONA值,PONA值是一个表征各种液体原料裂解性能的有实用价值的参数。
P—烷烃(Paraffin); O—烯烃(Olefin);N—环烷烃(Naphtene);A—芳烃(Aromatics)。
(2)氢含量,根据氢含量既可判断该原料可能达到的裂解深度,也可评价该原料裂解所得C4和C4以下轻烃的收率。
氢含量可以用裂解原料中所含氢的质量百分数表示,也可以用裂解原料中C 与H的质量比(称为碳氢比)表示。
(3)特性因数—K,K是表示烃类和石油馏分化学性质的一种参数。
K值以烷烃最高,环烷烃次之,芳烃最低,它反映了烃的氢饱和程度。
(4)关联指数—BMCI值,BMCI值是表示油品芳烃含量的指数。
关联指数愈大,则表示油品的芳烃含量愈高。
5. 温度和停留时间如何影响裂解反应结果?答:(1)高温:从裂解反应的化学平衡角度,提高裂解温度有利于生成乙烯的反应,并相对减少乙烯消失的反应,因而有利于提高裂解的选择性;根据裂解反应的动力学,提高温度有利于提高一次反应对二次反应的相对速度,提高乙烯收率。
(2)短停留时间:从化学平衡的角度:如使裂解反应进行到平衡,由于二次反应的发生,所得烯烃很少,最后生成大量的氢和碳。
第三章 消费税作业及参考答案

第三章消费税习题与答案一、单项选择题1.从概念上看,我国的消费税属于( )。
A.一般消费税B.特别消费税C.总量消费税D.收入消费税2.下列项目中,应征消费税的是( )。
A.啤酒屋销售的自制扎啤C.黄河牌卡车B.土杂商店出售的烟火鞭炮D.销售使用过的小轿车3.以下不属于征收消费税的项目是( )。
A.高尔夫球B.高尔夫球袋C.高尔夫球杆握把D.高尔夫车4.以下说法不正确的是( )。
A.果汁啤酒应按照啤酒税目征收消费税C.卡丁车不征收消费税B.动力艇不征收消费税D.香粉应按化妆品税目征收消费税5.消费税纳税义务人规定中的“中华人民共和国境内”,是指生产、委托加工和进口属于应当征收消费税的消费品的( )在境内。
A.生产地B.使用地C.起运地或所在地D.销售地6.征收消费税的车辆包括( )。
A.越野吉普车B.电动汽车C.沙滩车D.大客车7.下列应征收消费税的轮胎有( )。
A.拖拉机专用轮胎C.子午线轮胎B.拖拉机和汽车通用轮胎D.翻新轮胎8.以下应税消费品中,适用单一定额税率的有( )。
A.粮食白酒B.酒精C.黄酒D.啤酒9.下列商品售价中,与计算消费税的价格直接相关的是( )。
A.卡车出厂价C.钻石饰品的出厂价B.化妆品厂的戏剧卸妆油出厂价D.高尔夫球袋的出厂价10.下列应视同销售缴纳消费税的情况有( )。
A.将外购已税消费品继续加工成应税消费品B.将委托加工收回的应税消费品继续加工成应税消费品C.自制应税消费品继续加工成应税消费品D.自制应税消费品用于向外单位投资11.某非标准条包装卷烟每包25支,每条12包,不含增值税调拨价每条70元,则该卷烟每标准箱消费税额为( )。
A.3500元B.3650元C.4350元C.5250元12.某酒厂2012年1月份生产一种新的粮食白酒,广告样品使用0.8吨,已知该种白酒无同类产品出厂价,生产成本每吨40000元,成本利润率为10%,粮食白酒定额税率为每斤0.5元,比例税率为20%。
第三章作业本量利分析参考答案

第三章本-量-利分析一、单项选择题1.不是本量利关系基本公式的是( A )。
A.利润=单位贡献毛益×销售量-变动成本B.利润=单价×销售量-(销售量×单位变动成本+固定成本)C.利润=销售收入×贡献毛益率-固定成本D.利润=销售收入-固定成本-变动成本2.下列等式不成立的是( B )。
A.安全边际率+盈亏临界点作业率=lB.安全边际率+贡献毛益率=1C.变动成本率+贡献毛益率=lD.贡献毛益率×安全边际率=销售利润率3.某企业生产产品A,单位变动成本10元,年产销量均为5 000件,年固定成本10 000元,单位售价15元,则总的贡献毛益为( C )。
A.5 000 B.15 000 C.25 000 D.115 000 4.某企业只生产销售一种产品,该产品单位售价8元,单位变动成本5元,年固定成本为30 000元,则该产品的盈亏临界点销售额为( D )元。
注意:销售额与销售量的区别A.10 000 B.30 000 C.50 000 D.80 0005.其他条件不变,单价提高,则盈亏临界点( C )。
A.提高 B.不变 C.下降 D.A、B、C都有可能6. 在各种盈亏临界图中,( B )更符合变动成本法的思路。
A. 传统式B. 贡献毛益式C. 利量式D.单位式7.某产品的单价为10元,单位变动成本为5元,固定成本为20 000元,目标净利润为13 400元,所得税率为33%,则实现目标净利润的销售量为( A )。
【13400/(1-33%)+20000】/5A.8 000件 B.6 680件 C.8 0000件 D.66 800件8.正常盈利情况下,对利润最敏感的因素是( C )。
A.单位变动成本 B.固定成本 C.单价 D.销售量二、多项选择题1.其他因素不变时,会引起企业利润上升的有( ABCD )。
A.单价上升 B.销量增加C.单位变动成本下降 D.固定成本下降2.下列因素上升时,会导致盈亏临界点上升的因素为( BC )。
第三章作业参考答案

h( n) =
T − ( a + jb ) nT [e + e− ( a − jb ) nT ]u (n) 2
∞
H ( z ) = ∑ h( n) z − n =
n=0
T 1 1 [ ] + − aT − jbT −1 − aT jbT −1 2 1− e e z 1− e e z
模拟滤波器的幅频响应
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0
0.5
1
1.5
2
2.5
3
3.5
3.6 一个采样数字处理低通滤波器,H(z)的截止频率 wc = 0.2π ,整个系统相当于一个模拟 低通滤波器,今采样频率 fs=1kHz,求等效于模拟低通的边界频率 fc。若采样频率 fs 分别改 变为 5kHz,200Hz,而 H(z)不变,问这时等效的模拟低通的边界频率又为多少? 解: fc =
T 1+ z −1 s= i 2 1− z −1
=
1 1+ z 1 + z −1 2 1 + z −1 3 1 + 2( ) 2( ) +( ) + 1 − z −1 1 − z −1 1 − z −1
−1
=
(1 − z −1 )3 6 + 2 z −2
(1 − z −1 )3 (1 − e − jω )3 幅频响应: H (e ) = | jω = 6 + 2 z −2 z =e 6 + 2e −2 jω
2 3
H a ( s) =
1 + 2( s / Ω c ) + 2 ( s / Ωc ) + ( s / Ωc )
(完整版)《计算机网络》第三章作业参考答案

第三章作业参考答案3-03 网络适配器的作用是什么?网络适配器工作在哪一层?答:网络适配器功能主要包括:对数据进行串/并传输转换;对数据进行缓存;实现以太网协议;过滤功能;同时能够实现帧的传送和接收,对帧进行封装等。
网络适配器工作在物理层和数据链路层。
3-04 数据链路层的三个基本问题(帧定界、透明传输和差错检测)为什么都必须加以解决?答:封装成帧就是在一段数据的前后分别添加首部和尾部(在首部和尾部里面有许多必要的控制信息)构成一个帧。
接收端能从收到的比特流中准确地区分出一个帧的开始和结束在什么地方;透明传输使得不管所传数据是什么样的比特组合,都必须能够正确通过数据链路层,具体说就是解决二进制比特流中出现与帧定界符相同的位流问题;差错检测可以检测出有差错的帧,并将其丢弃掉,从而降低了数据传输的比特差错率。
3-07 要发送的数据为1101011011。
采用CRC的生成多项式是P(x)=x4+x+1 。
试求应添加在数据后面的余数。
数据在传输过程中最后一个1变成了0,问接收端能否发现?若数据在传输过程中最后两个1都变成了0,问接收端能否发现?采用CRC检验后,数据链路层的传输是否变成了可靠的传输?答:(1)因为P(x)=x4+x+1,所以p=10011。
n比p少一位,所以n=4采用CRC校验时,被除数是:11010110110000,除数是:10011,得余数1110。
即添加数据后面的余数(帧检验序列)是1110。
(2)若数据在传输过程中最后一个1变成了0,即11010110101110除以10011,得余数为0011,不为0,接收端可以发现差错。
(3)若数据在传输过程中最后两个1都变成了0,即11010110001110除以10011,得余数为0101,不为0,接收端可以发现差错。
(4)出现以上两种情况,由于接收端均发现错误,丢弃相应的帧,而CRC校验方法没有对应的重传机制,数据链路层并不能保证接收方接到的和发送方发送的完全一致,所以,在数据链路层的传输是不可靠的。
计算机网络第三章作业参考答案

Chapter3 THE DATA LINK LAYER2.The following data fragment occurs in the middle of a data stream for which thebyte-stuffing algorithm described in the text is used: A B ESC C ESC FLAG FLAG D. What is the output after stuffing?Answer:A B ESC C ESC FLAG FLAG D ==> A B ESC ESC C ESC ESC ESC FLAG ESC FLAG D3.What is the maximum overhead in byte-stuffing algorithm?Answer :This a frame delimited by flag bytes. (Ignore the header and trailer)Suppose that there is x bytes in payload field, and the worst case is that all of them are flag bytes or ESC, there should be 2x bytes in total. So the max overhead in byte-stuffing should be: 2+x x+1+111111lim=lim =lim +=+lim =2+2x 2x+122x+122x+12x x x x →∞→∞→∞→∞()()()() Or: (from 袁子超)if it has n bytes to send, and has m ESC. So the overhead is :.If the n bytes are all ESC, the overhead is maximum as :FLAG FLAG Payload field4.When bit stuffing is used, is it possible for the loss, insertion, or modification of a single bit to cause an error not detected by the checksum? If not, why not? If so, how? Does the checksum length play a role here?Answer:It is possible. Suppose that the original text contains the bit sequence 01111110 as data. After bit stuffing, this sequence will be rendered as 011111010. If the second 0 is lost due to a transmission error, what is received is 01111110, which the receiver sees as end of frame. It then looks just before the end of the frame for the checksum and verifies it. If the checksum is 16 bits, there is 1 chance in 216 that it will accidentally be correct, leading to an incorrect frame being accepted. The longer the checksum, the lower the probability of an error getting through undetected, but the probability is never zero.6.To provide more reliability than a single parity bit can give, an error-detecting coding scheme uses one parity bit for checking all the odd-numbered bits and a second parity bit for all the even-numbered bits. What is the Hamming distance of this code?Answer:Any single-bit error in the odd-numbered bits could change parity bit. It’s the same as the even-numbered bits. And both two errors occur in the odd-numbered bits or in the even-numbered bits will not change the parity bit. That is to say , this code could only detect single-bit errors, which means the Hamming distance is 2.7.An 8-bit byte with binary value 10101111 is to be encoded using an even-parity Hamming code. What is the binary value after encoding?According to rr m 2)1(≤++,m=8 r=4P1=B1⊕B3⊕B5⊕B7⊕B9⊕B11 =∑(0,1,0,0,1,1)=1P2=B2⊕B3⊕B6⊕B7⊕B10⊕B11=∑(0,1,1,0,1,1)=0P3=B4⊕B5⊕B6⊕B7 ⊕B12 =∑(0,0,1,0,1)=0P4=B8⊕B9⊕B10⊕B11⊕B12 =∑(0,1,1,1,1)=0So, Hamming code is: 10100100111113.Suppose that a message 1001 1100 1010 0011 is transmitted using Internet Checksum (4-bit word). What is the value of the checksum?Solution:100111001010+ 0011---------------------------------0010 (have 2 added bit),so:+1+1----------------------------------0100So, the Internet checksum is the ones complemnet of 0100, or 1011.14.What is the remainder obtained by dividing 751x x ++by the generator polynomial 31x +?42375745452424211111x x xx x x x x x x x x x x x xx x ++++++++++++++The remainder is 21x x ++.15.A bit stream 10011101 is transmitted using the standard CRC method described in the text. Thegenerator polynomial is ,. Show the actual bit string transmitted. Suppose that the third bit from the left is inverted during transmission. Show that this error is detected at the receiv er’s end. Give an example of bit errors in the bit string transmitted that will not be detected by the receiver.Solution:(1)→100110011101000 mod 1001 = 100The actual bit string transmitted: 10011101000+100=10011101100(2) The bit string receiver receives :10011101100→10111101100 10111101100 mod 1001 = 100 ≠ 0 →error!(3)example: 10011101100→1001111010110011110101 mod 1001 = 0So the receiver may think that the received bit string is right while it ’s wrong in fact.Data link protocols almost always put the CRC in a trailer than in a header. Why? Answer:CRC is calculated during sending. It could be appended to the data bit string as soon as the last data bit is send to the path. If it is put in the header, it must scan the whole frame in order to calculate CRC. It means that we should dispose the code 2 times. And CRC in the trailer could help to drop the half time.Or: (from 袁子超)CRC calculate during transmission. Once the last data sent out line, immediately put CRC code attached to the output stream from the back. If put CRC on the head of the frame, then we should check the frame to calculate CRC before sending. So that each byte has to deal with two times, the first is to calculate the check code, second times to send. Put CRC in the tail of the processing time can be halved.20.A 3000-km-long T1 trunk is used to transmit 64-byte frames using protocol 5. If the propagat ion speed is 6 μsec/km, how many bits should the sequence numbers be? Solution:delay= 3000-km* 6 μsec/km=18msBecause the bandwidth of T1 trunk = 1.544Mbps ,so:send time=64*8bits/1.544Mbps=0.33msthe time of send a frame and receive the acknowledge frame=18ms+0.33ms+18ms=36.33msthe number of frames: 36.33ms/0.33ms=11064=≤110≤=128sequence number should be 7 bitsFrames of 1000 bits are sent over a 1-Mbps channel using a geostationary satellite whose propagation time from the earth is 270 msec. Acknowledgements are always piggybacked onto data frames. The headers are very short. Three-bit sequence numbers are used. What is the maximum achievable channel utilization for(a) Stop-and-wait?(b) Protocol 5?(c) Protocol 6?Solution:Time for send a frame is: 1000bits/(1Mbps)=1msRound trip time: R=270ms*2=540msIt takes R+2=542ms to send a frame (be acknowledged).Therefore, a transmission cycle is 542ms. If the 542ms can send w frame, as a result of each frame transmission time is 1ms, the channel utilization rate is w/542.Three-bit sequence numbers are used, so the max window for (a),(b),(c) are :(a):W=1(b)1<W≤-1=7 →W=7(c)W≤=4→W=4So line utilization rate is: (a) 1*1ms/542ms * 100%=0.184%(b)7*1ms/542ms * 100%=1.292%(c)4*1ms/542ms*100%=0.738%30.Consider an error-free 64-kbps satellite channel used to send 512-byte data frames in one direction, with very short acknowledgements coming back the other way. What is the maximum throughput for window sizes of 1, 7, 15, and 127? The earth-satellite propagation time is 270 msec.Solution:Time for send a frame: 512*8bits/64kbps=64msSo, a transmission cycle: T=270ms*2+64ms=604ms and transmission window is:604ms/64ms=9.4,that’s mean: if w>9 the channel is full, the throughput cannot rise,(1)W=1: throughout=512*8b/604ms=6781bps=6.78kbps(2)W=7: throughout=7*512*8b/604ms=47.47kbps(3)(4) 15>9&&127>9, so throughout= 64kbps32.Give at least one reason why PPP uses byte stuffing instead of bit stuffing to prevent accidental flag bytes within the payload from causing confusion.Answer:(1) PPP was clearly designed to be implemented in software, not in hardware as HDLC nearly always is. With a software implementation, working entirely with bytes is muc h simpler than working with individual bits.(2) PPP was designed to be used with modems, and modems accept and transmit data in units of 1 byte, not 1 bit.33. What is the minimum overhead to send an IP packet using PPP? Count only the overhead introduced by PPP itself, not the IP header overhead. What is the maximum overhead?Solution:the PPP full frame format for unnumbered mode is:And Address and control could be ignored if sender and receiver have approve it.The minimum overhead=1+1+2+1=5bytesThe maximum overhead=1+1+1+2+4+1=10bytes。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第三章作业参考答案P181 第3题:答:现对进程语句进行编号,以方便描述。
P1:P2:begin beginy:=1; ①x:=1; ⑤y:=y+3; ②x:=x+5; ⑥V(S1); P(S1);z:=y+1; ③x:=x+y; ⑦P(S2); V(S2);y:=z+y ④z:=z+x; ⑧end. end.①、②、⑤和⑥是不相交语句,可以任何次序交错执行,而结果是唯一的。
接着无论系统如何调度进程并发执行,当执行到语句⑦时,可以得到x=10,y=4。
按Bernstein 条件,语句③的执行结果不受语句⑦的影响,故语句③执行后得到z=5。
最后,语句④和⑧并发执行,这时得到了两种结果为:语句④先执行:x=10,y=9,z=15。
语句⑧先执行:x=10,y=19,z=15。
此外,还有第三种情况,语句③被推迟,直至语句⑧后再执行,于是依次执行以下三个语句:z:=z+x;z:=y+1;y:=z+y;这时z的值只可能是y+1=5,故y=z+y=5+4=9,而x=10。
第三种情况为:x=10,y=9,z=5。
P181 第5题:解:设信号量empty,mutex;empty:=100;mutex:=1;parbegin读者进入:beginP(empty);P(mutex);登记;P(mutex);End;读者离开:beginP(mutex);撤消登记;V(mutex);V(empty);End;Parend ;P181 第6题:答:实质上是两个进程的同步问题,设信号量S1和S2分别表示可拣白子和黑子,不失一般性,若令先拣白子。
Main( ){ int S1=1, S2=0; CobeginP1( ); P2( ); Coend }P182第15题:Dijkstra 临界区软件算法描述如下:var flag:array[0…n] of (idle,want-in,in_cs);turn:integer;tune:0 or 1 or …or ,n-1; process Pi(i=0,1,…,n-1) var j;integer; begin repeatrepeatflag[i]:=want_in; while turn ≠i doif flag[turn]==idle then turn:=i; flag[i]:=in_cs; j:=0;while (j<n)&(j==i or flag[j]≠in_cs) do j:=j+1; until j ≧n; critical section; flag[i]:=idle; …until false;P1( ) { while(拣子工作没完成) { P(S1); 拣白子 V(S2); } } P2( ) { while(拣子工作没完成) { P(S2); 拣黑子 V(S1); } }end.试说明该算法满足临界区原则。
答:为方便描述,把Dijkstra程序的语句进行编号:repeatflag[i]:=want_in; ①while turn≠i do ②if flag[turn]==idle then turn:=i; ③flag[i]:=in_cs; ④j:=0;while (j<n)&(j==i or flag[j]≠in_cs) ⑤do j:=j+1; ⑥until j≧n;critical section;flag[i]:=idle; ⑦…(1)满足互斥条件当所有的Pj都不在临界区中,满足flag[j]≠in_cs (对于所有j,j≠i)条件时,Pi才能进入它的临界区,而且进程Pi不会改变除自己外的其他进程所对应的flag[j]的值。
另外,进程Pi总是先置自己的flag[i]为in_cs后,才去判别Pj进程的flag[j]的值是否等于in_cs,所以,此算法能保证n个进程互斥地进入临界区。
(2)不会发生无休止等待进入临界区由于任何一个进程Pi在执行进入临界区代码时先执行语句①,其相应的flag[i]的值不会是idle。
注意到flag[i]=in_cs并不意味着turn的值一定等于i。
我们来看以下情况,不失一般性,令turn的初值为0,且P0不工作,所以,flag[turn]=flag[0]=idle。
但是若干个其他进程是可能同时交替执行的,假设让进程Pj(j=1,2,..,n-1)交错执行语句①后(这时flag[j]=want_in),再做语句②(第一个while语句),来查询flag[turn]的状态。
显然,都满足turn≠i,所以,都可以执行语句③,让自己的turn为j。
但turn仅有一个值,该值为最后一个执行此赋值语句的进程号,设为k、即turn=k(1≤k≦n-1)。
接着,进程Pj(j=1,2,..,n-1)交错执行语句④,于是最多同时可能有n-1个进程处于in_cs状态,但不要忘了仅有一个进程能成功执行语句④,将turn置为自己的值。
假设{P1,P2,…Pm}是一个已将flag[i]置为in_cs(i=1,2,…,m)(m≤n-1)的进程集合,并且已经假设当前turn=k(1≤k≤m),则Pk必将在有限时间内首先进入临界区。
因为集合中除了Pk之外的所有其他进程终将从它们执行的语句⑤(第二个while循环语句)退出,且这时的j值必小于n,故内嵌until起作用,返回到起始语句①重新执行,再次置flag[i]=want_in,继续第二轮循环,这时的情况不同了,flag[turn]=flag[k]必定≠idle(而为in_cs)。
而进程Pk 发现最终除自身外的所有进程Pj的flag[j]≠in_c s,并据此可进入其临界区。
P183第21题:21.Jurassic公园有一个恐龙博物馆和一个花园,有m个旅客和n辆车,每辆车仅能乘一个旅客。
旅客在博物馆逛了一会,然后,排队乘坐旅行车,当一辆车可用时,它载入一个旅客,再绕花园行驶任意长的时间。
若n辆车都已被旅客乘坐游玩,则想坐车的旅客需要等待。
如果一辆车已经空闲,但没有游玩的旅客了,那么,车辆要等待。
试用信号量和P、V操作同步m个旅客和n辆车子。
答:这是一个汇合机制,有两类进程:顾客进程和车辆进程,需要进行汇合、即顾客要坐进车辆后才能游玩,开始时让车辆进程进入等待状态。
var scl,sck,sc,kx,xc,mutex:semaphore;sck := kx:= sc:= xc:=0;sc1:=n;mutex:=1;sharearea:一个登记车辆\被服务乘客信息的共享区;cobeginprocess 顾客i(i=1,2,…)beginP(scl); /*车辆最大数量信号量P(mutex); /*封锁共享区,互斥操作在共享区sharearea登记被服务的顾客的信息:起始和到达地点,行驶时间V(sck); /*释放一辆车,即顾客找到一辆空车P(kx); /*车辆要配备驾驶员,顾客等待被载,上车;V(sc); /*顾客进程已汇合到车辆进程,即顾客坐进车里P(xc); /*待游玩结束后后,顾客等待下车V(scl); /*空车辆数加1endProcess 车辆j(j=1,2,…)beginL: P(sck); /*车辆等待有硕客来使用在共享区sharearea登记那一辆车被使用,并与顾客进程汇合;V(mutex); /*这时可开放共享区,让另一顾客雇车V(kx); /*允许顾客用此车辆P(sc); /*车辆等待顾客上车车辆载着顾客开行到目的地;v(xc); /*允许顾客下车goto L;endcoendP184第24题:24.系统有A、B、C、D共4种资源,在某时刻进程P0、P1、P2、P3和P4对资源的占有和需求情况如表,试解答下列问题:(1)系统此时处于安全状态吗?(2)若此时P2发出request2(1、2、2、2),系统能分配资源给它吗?为什么?答:(1)系统处于安全状态,存在安全序列:P0,P3,P4,P1,P2。
(2)不能分配,否则系统会处于不安全状态。
P185第26题:答:1.由于系统目前还有150-25-40-45=40个单元,P4进程到达,把25个单元分给它。
这时系统还余15个单元,可把15个单元分给P3,它执行完后会释放60个单元。
于是可供P1(还要45个单元),P2(还要20个单元),P4(还要35个单元)任何一个执行。
安全序列为:P1,P2,P3,P4,P3,P1,P2,P4P1,P2,P3,P4,P3,P1,P4,P2P1,P2,P3,P4,P3,P2,P1,P4P1,P2,P3,P4,P3,P2,P4,P1P1,P2,P3,P4,P3,P4,P1,P2P1,P2,P3,P4,P3,P4,P2,P12.P4进程到达,P4最大需求60,最初请求35。
如果把35个单元分给P4,系统还余5个单元,不再能满足任何一个进程的需求,系统进入不安全状态。
P185第31题:解:semaphone wait, mutex1, mutex2;mutex1=mutex2=1;wait=1;int counter1, counter2;counter1=0; counter2=0;cobeginprocess P东( ){P(mutex1);counter1++;if(counter1==1)P(wait);V(mutex1);{过独木桥};P(mutex1);counter1--;if(counter1==0)V(wait);V(mutex1);}process P西( ){P(mutex2);counter2++;if(counter2==1)P(wait);V(mutex2);{过独木桥};P(mutex2);counter2--;if(counter2==0)V(wait);V(mutex2);}coendP185第32题:解:semaphone wait, mutex1, mutex2, bridge;mutex1=mutex2=1;bridge=k;wait=1;int counter1, counter2;counter1=0; counter2=0;cobeginprocess P东( ){P(mutex1);counter1++;if(counter1==1)P(wait);V(mutex1);P(bridge);{过独木桥};V(bridge);P(mutex1);counter1--;if(counter1==0)V(wait);V(mutex1);}process P西( ){P(mutex2);counter2++;if(counter2==1)P(wait);V(mutex2);P(bridge);{过独木桥};V(bridge);P(mutex2);counter2--;if(counter2==0)V(wait);V(mutex2);}coendP185第33题:解:semaphone wait, mutex1, mutex2;mutex1=mutex2=1;wait=1;int counter1, counter2;counter1=0; counter2=0;semaphone s1, s2;s1=3; s2=0;cobeginprocess P东( ){P(s1);P(mutex1);counter1++;if(counter1==1)P(wait);V(mutex1);{过独木桥};V(s2);P(mutex1);counter1--;if(counter1==0)V(wait);V(mutex1);}process P西( ){ P(s2);P(mutex2);counter2++;if(counter2==1)P(wait);V(mutex2);{过独木桥};V(s1);P(mutex2);counter2--;if(counter2==0)V(wait);V(mutex2);}coendP186第34题:解:semaphone wait, mutex1, mutex2;mutex1=mutex2=1;wait=1;int counter1, counter2;counter1=0; counter2=0;semaphone stop;stop=1;cobeginprocess P东( ){P(stop);P(mutex1);counter1++;if(counter1==1)P(wait);V(mutex1);V(stop);{过独木桥};P(mutex1);counter1--;if(counter1==0)V(wait);V(mutex1);}process P西( ){ P(stop);P(mutex2);counter2++;if(counter2==1)P(wait);V(mutex2);V(stop);{过独木桥};P(mutex2);counter2--;if(counter2==0)V(wait);V(mutex2);}coendP185第36题:解:36.答:当两个进程都执行完第一部(都占用R1)时,系统进入不安全状态。