I m 制造 n子;然后在屏障破碎后开始执行。
全球数据空间:
int bkdown = 0;
主要():
pthread_barrier_init(&bar,NULL,n);
for(i=0;i<n;i++)
{
pthread_create(&threadIdArray[i],NULL,runner,NULL);
if(i==n-2)printf("breakdown imminent!
");
if(i==n-1)printf("breakdown already occurred!
");
}
校对功能:
void *runner(void *param)
{
pthread_barrier_wait(&bar);
if(bkdown==0){bkdown=1;printf("barrier broken down!
");}
...
pthread_exit(NULL);
}
<>Expected order:
breakdown imminent!
barrier broken down!
breakdown already occurred!
<<>strong>Actual Order:(经多次测试)。
breakdown imminent!
breakdown already occurred!
barrier broken down!!
是否有人解释为什么我没有在<条码>上贴上“<>条/条码>的信息?