more task related question.. - VxWorks

This is a discussion on more task related question.. - VxWorks ; Come to think of it I have another question: With respect to priority task1 is the highest, task2 is the lowest. The snippet: SEM_ID task1_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY); SEM_ID task2_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY); void compute_like_crazy() { } void give_t1_sema() { ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: more task related question..

  1. more task related question..

    Come to think of it I have another question:


    With respect to priority task1 is the highest, task2 is the lowest. The

    snippet:


    SEM_ID task1_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
    SEM_ID task2_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY);


    void compute_like_crazy()
    {
    }


    void give_t1_sema() { semGive(task1_sema); }
    void give_t2_sema() { semGive(task2_sema); }

    void give_both_sema() {
    semGive(task1_sema);
    semGive(task2_sema);
    }


    void task1()
    {
    while (1)
    {
    if (semTake(task1_sema, WAIT_FOREVER) != OK)
    continue;
    std::cout << " task one started " << endl;

    for (int idx(0); idx < 10000; ++idx)
    {
    compute_like_crazy();
    taskDelay(sysClkRateGet() * 1);
    }
    std::cout << " hi there from task one " << endl;
    }



    }


    void task2()
    {
    while (1)
    {
    if (semTake(task2_sema, WAIT_FOREVER) != OK)
    continue;
    std::cout << " task two started " << endl;

    std::cout << " hi there from task two " << endl;
    }
    }


    I was surpised to learn that if I typed give_both_sema at the console
    prompt.
    The result prints:
    task one started
    task two started
    hi there from task two
    hi there from task one

    The reason for my suprise surrounds the fact that I was of the
    impression that the _highest_ priority task - in this case - task1
    (which executed first) is in control of the CPU. That said, task2 will

    literally have to 'wait' until task1 is complete before executing. The
    results show otherwise. 'hi there from task two' prints before 'high
    there from task one'. Does this mean task2 suspends 'task1' or .. what
    am I missing. Not sure how two task could execute at the same time?


    Being new to vxWorks I suspect it's time to pull out the manual again
    since I'm not sure my understanding of high and lower prority tasks are
    in synch with the output.


  2. Re: more task related question..

    Hello forums_mp,
    forums_mp@hotmail.com schrieb:
    > Come to think of it I have another question:
    >
    >
    > With respect to priority task1 is the highest, task2 is the lowest. The
    >
    > snippet:
    >
    >
    > SEM_ID task1_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
    > SEM_ID task2_sema = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
    >
    >
    > void compute_like_crazy()
    > {
    > }
    >
    >
    > void give_t1_sema() { semGive(task1_sema); }
    > void give_t2_sema() { semGive(task2_sema); }
    >
    > void give_both_sema() {
    > semGive(task1_sema);
    > semGive(task2_sema);
    > }
    >
    >
    > void task1()
    > {
    > while (1)
    > {
    > if (semTake(task1_sema, WAIT_FOREVER) != OK)
    > continue;
    > std::cout << " task one started " << endl;
    >
    > for (int idx(0); idx < 10000; ++idx)
    > {
    > compute_like_crazy();
    > taskDelay(sysClkRateGet() * 1);
    > }
    > std::cout << " hi there from task one " << endl;
    > }
    >
    >
    >
    > }
    >
    >
    > void task2()
    > {
    > while (1)
    > {
    > if (semTake(task2_sema, WAIT_FOREVER) != OK)
    > continue;
    > std::cout << " task two started " << endl;
    >
    > std::cout << " hi there from task two " << endl;
    > }
    > }
    >
    >
    > I was surpised to learn that if I typed give_both_sema at the console
    > prompt.
    > The result prints:
    > task one started
    > task two started
    > hi there from task two
    > hi there from task one
    >
    > The reason for my suprise surrounds the fact that I was of the
    > impression that the _highest_ priority task - in this case - task1
    > (which executed first) is in control of the CPU. That said, task2 will
    >
    > literally have to 'wait' until task1 is complete before executing. The
    > results show otherwise. 'hi there from task two' prints before 'high
    > there from task one'. Does this mean task2 suspends 'task1' or .. what
    > am I missing. Not sure how two task could execute at the same time?
    >


    No, the task is never suspended since it is the wrong wording. It will
    enter the task state of pending due to the task1 call tasl_delay() which
    implicitely makes the highest task task2, since there is no other task
    in the system ready for using the CPU (this is taking task1 and task2
    into account ONLY!)

    Hope it helps.

    PS: It would be a nice thing that you tell us your name, I suspect
    forums_mp is not a name of a natuarl person.

    --
    BaSystem Martin Raabe
    E: Martin.RaabeB-a-S-y-s-t-e-mde

  3. Re: more task related question..


    || No, the task is never suspended since it is the wrong wording. It
    will enter the task state of pending due to
    || the task1 call tasl_delay() which implicitely makes the highest
    task task2,
    || since there is no other task in the system ready for using the CPU
    || (this is taking task1 and task2 into account ONLY!)

    I see. So because of the taskDelay, task2 (the lower of the two) will
    relinquish the CPU. Lets assume there was no 'taskDelay' and
    compute_like_crazy was doing some algorithm intensive 'stuff' that took
    approximately 1 sec. In this case task2 will 'wait' (perhaps wrong
    terminology again) for task1 to relinquish the CPU? Correct?


  4. Re: more task related question..

    Hello forums_mp,

    forums_mp@hotmail.com schrieb:
    > I see. So because of the taskDelay, task2 (the lower of the two) will
    > relinquish the CPU. Lets assume there was no 'taskDelay' and
    > compute_like_crazy was doing some algorithm intensive 'stuff' that took
    > approximately 1 sec. In this case task2 will 'wait' (perhaps wrong
    > terminology again) for task1 to relinquish the CPU? Correct?
    >


    Correct!
    Try coding a for loop in the compute_like_crazy() with the duration
    of 1 second for test purpose and you will see!



    --
    BaSystem Martin Raabe
    E: Martin.RaabeB-a-S-y-s-t-e-mde

  5. Re: more task related question..


    Thank you. It's coming together slowly but surely.


+ Reply to Thread