Forum Discussion
Altera_Forum
Honored Contributor
15 years agoCrash and semaphores
Hi, when I make three tasks synchronized by semaphores (the tasks do nothing, they only make a Post and then a Pend to pass the control each other), after a number of iterations (this number i...
Altera_Forum
Honored Contributor
15 years agoThank you for the interesting.
The code is: #include "includes.h" #include <iostream> using namespace std; #define OS_TASK_STAT_EN 1 #define OS_MAX_TASKS 8 #define TASK_STK_SIZE 1024 OS_STK TaskStartStk[TASK_STK_SIZE]; OS_STK TaskStartStk1[TASK_STK_SIZE]; OS_STK TaskStartStk2[TASK_STK_SIZE]; OS_STK TaskStartStk3[TASK_STK_SIZE]; OS_EVENT* sem_sync0; OS_EVENT* sem_sync1; OS_EVENT* sem_sync2; OS_EVENT* sem_sync3; void handle_sync(void* pdata) { INT8U err_sync3; pdata = pdata; for(;;) { cout << "I'm in handle_sync" << endl; fflush(0); OSSemPost(sem_sync1); OSSemPend(sem_sync3, 0, &err_sync3); } } void processing(void* pdata) { INT8U err_sync1; pdata = pdata; for(;;) { cout << "I'm in processing" << endl; fflush(0); OSSemPost(sem_sync2); OSSemPend(sem_sync1, 0, &err_sync1); } } void monitoring(void* pdata) { INT8U err_sync2; pdata = pdata; for(;;) { cout << "I'm in monitoring" << endl; fflush(0); OSSemPost(sem_sync3); OSSemPend(sem_sync2, 0, &err_sync2); } } static void TaskStartCreateTask(void) { cout << "I'm in TaskStartCreateTask" << endl; fflush(0); OSTaskCreate(handle_sync, (void*) 0, &TaskStartStk1 [TASK_STK_SIZE - 1], 11); OSTaskCreate(processing, (void*) 0, &TaskStartStk2[TASK_STK_SIZE - 1], 12); OSTaskCreate(monitoring, (void*) 0, &TaskStartStk3[TASK_STK_SIZE - 1], 15); } void TaskStart(void* pdata) { INT8U err_sync0; cout << "I'm in TaskStart" << endl; fflush(0); pdata = pdata; OSStatInit(); OSTaskCreate(handle_sync, (void*) 0, &TaskStartStk1[TASK_STK_SIZE - 1], 11); OSTaskCreate(processing, (void*) 0, &TaskStartStk2[TASK_STK_SIZE - 1], 6); OSTaskCreate(monitoring, (void*) 0, &TaskStartStk3[TASK_STK_SIZE - 1], 15); for(;;) { OSSemPost(sem_sync3); OSSemPend(sem_sync0, 0, &err_sync0); } } int main() { OSInit(); sem_sync0 = OSSemCreate(0); sem_sync1 = OSSemCreate(0); sem_sync2 = OSSemCreate(0); sem_sync3 = OSSemCreate(0); cout << "I'm in the main" << endl; fflush(0); OSTaskCreate(TaskStart, (void*) 0, &TaskStartStk[TASK_STK_SIZE - 1], 18); OSStart(); }