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,但是有具体过程吗,球球
全部评论
(0) 回帖