【发布时间】:2018-10-22 14:33:41
【问题描述】:
我使用 CBMC 来验证我的 Pthreads 程序,它检测到一些我认为不存在的断言错误。该错误仅在我同时运行两个线程时发生。也就是说,当我将调用线程函数的语句(func 或func1)放入注释时,CBMC 就可以验证它是否成功。数组a和b的赋值有冲突吗?
int a[4], b[4];
static void * func(void * me)
{
int i;
for(i=0; i<2; i++){
a[i] = b[i] = i;
assert( a[i] == i ); //failed
}
return ((void *) 0);
}
static void * func1(void * me)
{
int i;
for(i=2; i<4; i++){
a[i] = b[i] = i;
assert( a[i] == i ); //failed
}
return ((void *) 0);
}
int main(){
pthread_t thr1;
pthread_create(&thr1, NULL, func1, (void *)0);
(*func)(0);
pthread_join(thr1,NULL);
return 0;
}
CBMC的输出如下:
Violated property:
file pthreads4.c line 25 function func1
assertion a[i] == i
a[(signed long int)i] == i
VERIFICATION FAILED
【问题讨论】: