我正在尝试spinlockIsr_t
在 vxWorks 6.7 中使用,但如果我尝试将它用于多个任务,系统会冻结。您是否允许使用多个尝试获取相同自旋锁的任务?如果不是,那么首先它的意义是什么?以下代码适用于 1 或 2 个任务,但一旦任务数量增加到 3 个,系统就会冻结,然后才能在控制台上完成打印第一行。
spinlockIsr_t mySpinLock;
int sharedResource;
void vx_test_mtx_spin_lock(void)
{
const int kNumTask = 3;
const int kTaskPriority = 50;
const int kTaskStackSize = 10000;
int i = 0;
sharedResource = 0;
char procName[40];
printf("Number of tasks : %d\n", kNumTask);
printf("SPIN_LOCK_ISR_INIT() [main task]\n");
SPIN_LOCK_ISR_INIT (&mySpinLock, 0); printf("SPIN_LOCK_ISR_TAKE() [main task] \n");
SPIN_LOCK_ISR_TAKE (&mySpinLock);
for (i = 0; i < kNumTask; i++){
sprintf(procName, "%s%d", "myTask", i); printf("taskSpawn() [main task]\n");
taskSpawn((char*)procName,
kTaskPriority,
0,
kTaskStackSize,
(FUNCPTR)vx_spin_lock_unlock,
0,0,0,0,0,0,0,0,0,0
);
} printf("SPIN_LOCK_ISR_GIVE() [main task]");
SPIN_LOCK_ISR_GIVE (&mySpinLock);
}
void vx_spin_lock_unlock(void)
{
printf("SPIN_LOCK_ISR_TAKE() [spawned task] \n");
SPIN_LOCK_ISR_TAKE (&mySpinLock);
/* ... Access the share resource here */ printf("SPIN_LOCK_ISR_GIVE() [spawned task] \n");
SPIN_LOCK_ISR_GIVE (&mySpinLock);
}