测试notify前想先测试2个核的semaphore传递信号,程序很简单:
在.cfg里加入semaphore,并设为0: Program.global.semHandle = Semaphore.create(0);
在.c文件的任务里加入如下语句:0核打印,打印完释放semHandle ,1核等semHandle ,semHandle 来的打印:
coreId = CSL_chipReadReg (CSL_CHIP_DNUM);
switch(coreId)
{
case 0:
platform_write("Core %d is working! \n",coreId);
for(i=0;i<3;i++)
{
platform_write("Core %d is working on count %d! \n",coreId,i);
}
Semaphore_post(semHandle);
platform_write("Core %d Mission Complete,and Semaphore is %d \n",coreId,Semaphore_getCount(semHandle));
break;
case 1:
Semaphore_pend(semHandle,BIOS_WAIT_FOREVER);
platform_write("Core 1 is working! \n");
for(i=0;i<Led_Light_Cnt;i++)
{
platform_write("Core 1 is working on count %d! \n",i);
}
break;
default:
break;
}
可是运行结果总是0核打印正常,Semaphore_post 之后 Semaphore 也为1了,可是1核就是不打印啊!为啥?
Nancy Wang:
core1是无法执行到打印部分吗?core1中Semaphore_pend之前Semaphore_getCount获取的Sem值是1吗?
Lucius Green:
回复 Nancy Wang:
core1无法执行到打印部分,core1中Semaphore_pend之前的语句都可以执行,Semaphore_getCount获取的Sem的值是0.
coreo中 post 之后Semaphore_getCount的值为1.
Lucius Green:
回复 Nancy Wang:
Thanks ,Nancy.得到答案浑身都舒服了,啊哈哈,这个问题卡了2天了。