我声明了一个变量sum
并初始化为 0 ,然后通过函数func()
将其传递给函数pthread_create()
。我没想到的是变量sum
不再等于 0 (如您所见,函数assert()
失败了)。我的Ubuntu版本是16.04.4 LTS。
当我仅使用 GCC 进行编译时,就可以了,该错误是由 CBMC 报告的。
static void * func(void * arg)
{
double *sum = (double *)arg;
assert(*sum == 0.0); //failed in CBMC
return ((void *) 0);
}
int main(){
double sum=0.0;
pthread_t thr1;
pthread_create(&thr1, NULL, &func, (void *)&sum );
pthread_join(thr1, NULL);
printf("sum = %f\n", sum);
assert(sum == 0.0); //successful in CBMC
return 0;
}
以下是 CBMC 报告的警告:
State 70 file pthreads4.c line 24 function main thread 1
----------------------------------------------------
arg=&sum!0@1 (0000010000000000000000000000000000000000000000000000000000000000)
State 71 file pthreads4.c line 12 function func thread 1
----------------------------------------------------
sum=((double *)NULL) (0000000000000000000000000000000000000000000000000000000000000000)
State 72 file pthreads4.c line 12 function func thread 1
----------------------------------------------------
sum=&sum!0@1 (0000010000000000000000000000000000000000000000000000000000000000)
Violated property:
file pthreads4.c line 14 function func
assertion *sum == 0
IEEE_FLOAT_EQUAL(*sum, (double)0)
VERIFICATION FAILED