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.

RTOS: TI-RTOS Mutex Problem

Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Excuse me when I'm using a mutex whether with or without priority inheritance to block a task from being executed until the mutex is released the task isn't blocked at all
I tested it with the simple code below.

void(myfunc)(void)
{

while(1)
{
key=GateMutexPri_enter (gateMutexPri0);

counter++;

//GateMutexPri_leave(gateMutexPri0, key);
}
}

When the last line that releases the mutex is commented the counter keeps incriminating with no regard whatsoever to the mutex.

code composer version used is 6.1.2, sysbios version 6.40.3.9 and the XDC version is 3.31.0.24

  • Hi Ahmed,

    We are missing some information.

    Which device are you using?

    Is TI-RTOS used from ROM?

    How many tasks do you have?

    Where did you declare the key variable? The key variable should declared in the function only, not global.

    Are you saying that other tasks are not blocked when they try to enter the gate mutex?

    Just to be sure that you understand: if the same task attempts to enter the mutex, the gate mutex will allow it.

    If one task enters the mutex and another task then attempts to enter that same mutex, it should block it until it is released.

    Regards,

    Michel

  • TI-RTOS is used from the ROM yes.

    Device used is am437x sitara processor.

    in my code the mutex is being used inside a function that is called in different tasks to ensure that it's re-entrance but the key is defined globally in another file and being declared in the file where the task implementation is, not locally to the task as such:

    extern IARG key;

    void myfunc()
    {
    key=GateMutexPri_enter (gateMutexPri0);

    // do some code here

    GateMutexPri_leave(gateMutexPri0, key);
    }

    --------------------------------------------------------------------------------------------------------------------------------------------------

    void taskfn()
    {
    myfunc();
    }

    the key is globally declared in the file where myfunc() implementation is.

    To make sure that I understand you quite right what must be done is the next code, that will make sure that the key is defined locally to the function each time it's called.

    void myfunc()
    {
    IARG key;

    key=GateMutexPri_enter (gateMutexPri0);

    // do some code here

    GateMutexPri_leave(gateMutexPri0, key);
    }

  • And another question please.
    "if the same task attempts to enter the mutex, the gate mutex will allow it."
    I want to to stop the same task from re-entering, if the resource isn't released while using the priority inheritance that the gate mutex provides. What can I use to do this?
    Thanks in advance.
  • Ahmed Adel92 said:
    To make sure that I understand you quite right what must be done is the next code, that will make sure that the key is defined locally to the function each time it's called.

    Yes. That is correct.

    Ahmed Adel92 said:
    I want to to stop the same task from re-entering, if the resource isn't released while using the priority inheritance that the gate mutex provides. What can I use to do this?

    What you are describing above would cause a deadlock.

    If your task blocks on an event, how can it release the resource since you task will be blocked and waiting on itself?

    But if you wanted to do it, you could do that with a semaphore with a max count of 1. You also have to initialize it with an initial count of 1 so it is readily available.

    Regards,

    Michel