This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

程序执行顺序错误的原因



自己写了一段小程序,想要实现core0和core1之间的数据通信。

其中使用了全局变量flag作为标志位,指示core0是否完成数据的操作。

软件:ccs5.4

6678软仿。

运行的步骤:先在core0中跑,然后手动切换到core1中跑相同的程序。

问题:当切换到core1中时,发现程序执行完CACHE_invL1d(data,1,CACHE_WAIT);   后会跳到  if(DNUM == 0)  中的  if(i==100) 处开始执行,请问这是因为什么??

#include <stdio.h>
#include <c6x.h>
#include <csl_cacheAux.h>

int data[100],i,flag;

int main(void)
{

	if(DNUM == 0)
	{
		flag=0;
		for(i=0; i<100; i++)
		{
			data[i]=i+1;
		}
		CACHE_wbL1d(data,1,CACHE_WAIT);
		if(i==100)
		{
			printf("data has prepared!");
			flag=1;
			CACHE_wbL1d(&flag,1,CACHE_WAIT);
		}
	}

	if(DNUM==1)
	{
		CACHE_invL1d(&flag,1,CACHE_WAIT);
		if(flag==1)
		{
			CACHE_invL1d(data,1,CACHE_WAIT);
			for(i=0;i<100; i++)
			{
				data[i]=data[i]+DNUM;
			}
		}
	}
	return 0;
}