[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>操作系统错题总结
<>题目原题
这道题又是一道2016年的统考真题,真的怀疑那一年的题目的地狱级别…
简单先说一下同步与互斥的概念(根据进程的并发性,必须制定同步互斥规则使程序正确运行):
进程同步:
又称直接制约关系,就是A事件必须发生在B事件之前,B事件只能够在A事件发生后发生。
进程互斥:
又称间接制约关系,就是计算机的某些临界资源一次只可以被一个进程访问。(举个例子,两个人不能同时用一个马桶…)
下面我们可以一步步正解出答案:
A选项,a1、a2均为线程内的临时变量,赋值依旧也不改变最终结果。
B选项,a=x、b=x要求 “b=x”发生在之后,要求的是需要同步执行。
D选项,x+=1、x+=3并不在同一个进程之中,两个x并不相同,故无任何关联。
刚开始看到答案时,有些小伙伴应该会不解,其实我也是这样的。
认为
x = 0; ---->a. x += 1; ---->b. x += 2; //这两句没毛病啊,无论谁先执行结果都该是 3啊!!
其实这样理解是错的,这是因为高级语言编译器自动帮我们实现了变量操作访问的互斥机制。
站在计算机的立场应该是这样的(每个高级语言都包含若干条机器指令),
因为博客不会排版,直接写出来了,哈哈,大家凑活看:
所以,若不对 x += 1 和 x += 3进行互斥操作的话,结果确实是有很多种,所以选项C是正确的。
解决成功!