Deletion of Semaphore which is attached to a terminated Task leads to OS Error

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Deletion of Semaphore which is attached to a terminated Task leads to OS Error

    I have the following scenario:
    - Following sequence is executed in Task X:
    - Create Semaphore S (with OS_CreateSema()) with initial value of 0
    - Create Task A and hand over Semaphore S
    - Allow startup of Task A by using OS_Delay()
    - Task A approaches OS_WaitCSem() and hence waits for the release of Semaphore S (as the init value has been set to 0)
    - Task X terminates Task A by using OS_Terminate()
    - Task X deletes Semaphore S ---> this leads to OS error because the semaphore was used by the already terminated Task A

    How can I avoid that situation but still making sure that all resources are freed up at the end?
  • Hello,
    terminating a task by a call of OS_Terminate() should release all "waitable" objects the task is waiting at.
    The wait list of the semaphore should be empty after termination of the waiting task.
    I verified this by a simple modification of our "Start2Tasks" sample from embOS:
    static OS_CSEMA _CSema;

    static void HPTask(void) {
    OS_CreateCSema(&_CSema, 0);
    while (1) {
    OS_WaitCSema(&_CSema);
    OS_Delay (10);
    }
    }

    static void LPTask(void) {
    unsigned char RunFirst;

    RunFirst = 1;
    while (1) {
    if (RunFirst) {
    OS_Terminate(&TCBHP);
    OS_DeleteCSema(&_CSema);
    RunFirst = 0;
    }
    OS_Delay (50);
    }
    }

    Which embOS version are you using?
    Which compiler?
    Which CPU?