This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about Semaphores

Hi ,

I am checking the page34 of«rl-arm_gs» and find below description :

Signaling
Synchronizing the execution of two tasks is the simplest use of a semaphore:

os_sem semB;
__task void task1 (void) {
os_sem_init (semB, 0);
while (1) {
os_sem_send (semB);
FuncA();
}
}
__task void task2 (void) {
while (1) {
os_sem_wait (semB, 0xFFFF);
FuncB();
}
}


In this case, the semaphore is used to ensure that the code in FuncA() is executed
before the code in FuncB().

My questions is,

when the task1 will be suspended and the scheduler will start task2? I add above codes into one keil project and find actually task2 will not start for ever.

I think that such description above in italics is incorrect, isn't it?

Parents
  • here are my codes:

    #include <RTL.h>                      /* RTX kernel functions & defines      */
    #include <LPC21xx.H>                  /* LPC21xx definitions                 */
    #include <stdio.h>
    
    OS_TID tsk1, tsk2;
    OS_SEM semB;
    int counter1=0;
    int counter2=0;
    
    __task void task1 (void) {
          os_sem_init (semB, 0);
            while (1) {
            os_sem_send (semB);
            counter1 ++ ;
        }
    }
    
    
    __task void task2 (void) {
    
      while(1){
       os_sem_wait (semB, 0xFFFF);
       counter2++;
    }
    }
    
    __task void init (void) {
    
      tsk1 = os_tsk_create (task1, 10);
    
      tsk2 = os_tsk_create (task2, 10);
    
      os_tsk_delete_self ();
    }
    
    int main (void) {
    
      os_sys_init (init);
    }
    

    even round-robin option in config wizard is checked, task2 never starts, either.

Reply
  • here are my codes:

    #include <RTL.h>                      /* RTX kernel functions & defines      */
    #include <LPC21xx.H>                  /* LPC21xx definitions                 */
    #include <stdio.h>
    
    OS_TID tsk1, tsk2;
    OS_SEM semB;
    int counter1=0;
    int counter2=0;
    
    __task void task1 (void) {
          os_sem_init (semB, 0);
            while (1) {
            os_sem_send (semB);
            counter1 ++ ;
        }
    }
    
    
    __task void task2 (void) {
    
      while(1){
       os_sem_wait (semB, 0xFFFF);
       counter2++;
    }
    }
    
    __task void init (void) {
    
      tsk1 = os_tsk_create (task1, 10);
    
      tsk2 = os_tsk_create (task2, 10);
    
      os_tsk_delete_self ();
    }
    
    int main (void) {
    
      os_sys_init (init);
    }
    

    even round-robin option in config wizard is checked, task2 never starts, either.

Children