Task priority

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

  • Task priority

    Hello,
    I would like to ask about task priority.

    I have two task:
    TaskA - priority 242
    TasbB - priority 243

    TaskA call function: Log( "Tom", "No money");

    Source Code

    1. SetLog(string Name, string Error)
    2. {
    3. Log.Name = Name;
    4. Log.Error = Error;
    5. Log,Time = GetNow();
    6. WriteLog();
    7. }

    ( It is just example, it is not C code. Log is global struct)

    Lets say TaskA is on line "Log.Error = "No money"; " Can be TaskB now become active? TaskB call same function with different Name and Error.
    Data will by corrupted? So I have to use mailboxes? Is there any way how to check possible data conflict?
  • RE: Task priority

    Dear Rebel,

    Rebel wrote:

    Lets say TaskA is on line "Log.Error = "No money"; " Can be TaskB now become active?

    The scheduler will activate the task that has the highest priority of all tasks in the READY state. Hence, if Task B becomes ready while Task A is being executed, Task A gets preempted and Task B will become active. Further information may also be found inside our User & Reference Guide for embOS, chapter 2.4 ("Scheduling").

    Rebel wrote:

    TaskB call same function with different Name and Error. Data will by corrupted?

    Of course. Task A changes Log.Name after Task B has changed Log.Name. Hence, when Task B is resumed, Log.Name will contain the name that was assigned to it by Task A.

    Rebel wrote:

    So I have to use mailboxes? Is there any way how to check possible data conflict?

    embOS offers several ways to achieve thread safety. These include, but are not limited to, critical regions (see chapter 16 of the User & Reference Guide for embOS), disabling of interrupts (see chapter 15), and the usage of semaphores (chapters 6 & 7).

    Please let me know if I can be of any further help.

    Best regards,
    Martin