We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
In http://www.keil.com/support/docs/2568.htm I found code about semaphore:
/*--------------------------------------------------------- ---------------------------------------------------------*/ #pragma disable static char _Xget_semaphore ( unsigned char semaphore_id) { if (sem_tab[semaphore_id].count > 0) { --sem_tab[semaphore_id].count; return (-1); } sem_tab[semaphore_id].waiting_task_bits |= (1 << os_running_task_id()); return (0); }
My question is that: In RTX51 Tiny System, I have multi-tasks: A and B. task A already got semaphore, program is running after if (sem_tab[semaphore_id].count > 0) and will descrease sem_tab[semaphore_id].count. At the moment, another task B want to get semaphore, so call get_semaphore. Because count still stay 1 so enter char _Xget_semaphore function. Well, both of task A and B got semaphore now. I think this supposition is rare, but when it occur, it will make system something wrong. So, how could a semaphore function prevent the situation occur? Can be there any protection in code?
Thank you for help.
Ok, I got it, thank your for your explaining.