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,但是有具体过程吗,球球

#学习路径#
全部评论

相关推荐

水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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