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

#学习路径#
全部评论

相关推荐

用微笑面对困难:你出于礼貌叫了人一声大姐,大姐很欣慰,她真把你当老弟
点赞 评论 收藏
分享
活泼的代码渣渣在泡池...:哈哈哈挺好的,我也上岸美团了,不说了,我又接了一单
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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