Re: semBCreate, SEM_Q_FIFO



The problem is definitely one of context switching and scheduling.

The two tasks (test1 and test2) were at the same priority. If I
remember correctly, the default scheduling is round-robin. This means
that until test1 blocks (or possibly is scheduled out due to a higher
priority task coming in), test2 will not run.

Therefore one must induce a context switch to get the desired test1
test2 test1 test2 ... result. One way to do this is (as pointed
out earlier) to call taskDelay (0). This is a perfectly acceptable
solution so long as test2 is ready to run when taskDelay(0) is called.

In another example, it was suggested to initialize the binary
semaphore to empty and then give the semaphore. This too is a
perfectly acceptable solution provided that both test1 and test2
haveare pending on that semaphore before it is given.

I just wanted to draw attention to the underlying assumptions in the
examples. Their bite has caused me some frustration in the past, and
I just wanted to help others avoid their bite in the future.


On Feb 19, 6:37 am, "benelli.giac...@xxxxxxxxx"
<benelli.giac...@xxxxxxxxx> wrote:
On Feb 19, 11:00 am, aeromarine <hongw...@xxxxxxxxx> wrote:



On 2월19일, 오후5시26분, Alexander Lenherr <alenh...@xxxxxxxxxxxxxxxxxxx>
wrote:

One problem could be that task 1 already has finished his work BEFORE
task 2 gets started (between the two task spawns).
Have you tried to increase the upper limit of i in the test routines?

Regards,
Alexander

I changed for to while.. I got a same result.
only test1, test1, test1, .....

void test1() {
while(1){
semTake(sem1, WAIT_FOREVER);
printf("test1\n");
semGive(sem1);
}

}

void test2() {
while(1){
semTake(sem1, WAIT_FOREVER);
printf("test2\n");
semGive(sem1);
}

}- Hide quoted text -

- Show quoted text -

Hi, I think the problem is the initialization of the semaphore. If you
create it as SEM_FULL, it will be available to the first one that
takes it. So this is what happen:
- sem1 is available
- task1 tries to take it and succeds, so it prints its messages and
gives again sem1
- next iterations of task1 will be so fast that task1 will finish
before task2 ever has started.

You should initialize sem1 as SEM_EMPTY. The two tasks will pend for
sem1 at the beginning of the loop. Then you should add a semGive
instruction at the end of you main to unlock the tasks. You should see
task1 as the first to be unlocked because it has pended for a longer
time ( being the first to be spawned).

The correct code for main should be:

int main(){
sem1 = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
taskSpawn ("test1", 100, 0, 20000, (FUNCPTR)
test1,0,0,0,0,0,0,0,0,0,0);
taskSpawn ("test2", 100, 0, 20000, (FUNCPTR)
test2,0,0,0,0,0,0,0,0,0,0);
semGive(sem1);
return 0;

}

Let me know, bye!

Giacomo

.



Relevant Pages

  • Re: semBCreate, SEM_Q_FIFO
    ... the default scheduling is round-robin. ... that until test1 blocks (or possibly is scheduled out due to a higher ... solution so long as test2 is ready to run when taskDelayis called. ... next iterations of task1 will be so fast that task1 will finish ...
    (comp.os.vxworks)
  • Re: semBCreate, SEM_Q_FIFO
    ... The two tasks (test1 and test2) were at the same priority. ... the default scheduling is round-robin. ... next iterations of task1 will be so fast that task1 will finish ...
    (comp.os.vxworks)
  • Re: semBCreate, SEM_Q_FIFO
    ... The two tasks (test1 and test2) were at the same priority. ... the default scheduling is round-robin. ... next iterations of task1 will be so fast that task1 will finish ...
    (comp.os.vxworks)
  • Re: Junit newbie
    ... > time in junit versus my actual class. ... > iteratively test de/compressing a single byte array with the values ranging ... As to what if test2 requires test1 to pass? ...
    (comp.lang.java.help)
  • Re: Changing the local admin password base on the computers OU
    ... You can put the common code of the two IF-bodies in front of them, ... 'Change the local admin pwd for OU TEST1 ... 'Change the local admin pwd for OU TEST2 ... I do not know what it means to test for a computers membership in ...
    (microsoft.public.scripting.vbscript)