作者BDFishX (便当鱼X)
看板TransCSI
标题Re: [问题] 作业系统
时间Sun Aug 29 07:10:40 2010
※ 引述《sky810675 (KKMAN)》之铭言:
A function is called reentrant if its computation results are correct even if
invoked by two or more processes simultaneously. Check if the following
function is reentrant. If it is not, modify it so that it is reentrant. You
can assume that you have synchronization primitives provided by an operating
system.
static int iCount;
mutex mutex_iCount;
void foo(int x, int *p) {
int y;
y = x * 7;
++p;
*p = 5678;
lock(&mutex_iCount);
iCount *= 7890;
printf(“\nNew count: %d”, x);
unlock(&mutex_iCount);
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.123.101.251
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.64.100.16