Suppose that a shared variable

Suppose that a shared variable total (initialized as 0 ) can be accessed by the process P0 and P1. If the following processes execute concurrently, what is the probable minimum result of total?

P1:
{
    int count;
    for ( count =1; count <= 50; count++ )
        total = total + 1;
}
P2:
{
    int count;
    for ( count =1; count <= 50; count++ )
        total = total + 1;
}

有可能先 total + 1;寄存器里放了个1,然后跑到p2了,这时候total还没变成2,他又total+1,寄存器是2,但是count没变,就一直这样,[1]
[1]但是count 也不会++了啊,count++的前提是 total 那句已经做过了,确实
(1分)

A.1
B.2
C.3
D.50
答案是 B 2,但是有具体过程吗,球球

#学习路径#
全部评论

相关推荐

08-23 20:17
四川大学 C++
xxxzsfa:技术栈可以参考我这个给写,把知识点写出来起码能让面试官知道你是知道这个点的,不会的知识点可以不写,简历上写了但又答不上来就很尴尬了,可以给技术栈中的知识点和项目中的难点亮点加粗,学历不错,肯定会有大厂面的,刚开始可以先投中小厂练手,拿个offer保底再去面大厂,秋招可以正式和实习一起找,找工作是个需要长期坚持的过程,加油查看图片
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务