more task related questions..

F

forums_mp

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,129
Latest member
FastBurnketo
Top