Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTOS(RTX OS) Mutex_Semaphore Problem

Status
Not open for further replies.

LOSTISLAND

Member level 3
Joined
Jun 8, 2010
Messages
54
Helped
6
Reputation
12
Reaction score
5
Trophy points
1,288
Activity points
1,682
Hi all ,
I thought the only differences between a Mutex and a semaphore are the count(Semaphore Capability) and priority inversion(Mutex Capability) .
Today , I’ve encountered something strange which maybe is related to the priority inversion capability or something else .
Getting and releasing Mutex or Semaphores between different tasks is clear but when I use them in just one task , their behavior is different .
Using semaphore the task is locked but using Mutex the task is not locked .
Imagine there is just one task called APP_TestTask
Code:
__task void APP_TestTask (void) 
{ 
   for (;;) 
   { 
      os_dly_wait (20); 
      os_sem_wait(Sem_Test,0xffff); 
      os_sem_send(Sem_Test); 
      os_sem_wait(Sem_Test,0xffff); 
      os_sem_wait(Sem_Test,0xffff); 
      Test_Function(); 
   } 
}
Code:
_task void APP_TestTask (void) 
{ 
   for (;;) 
   { 
      os_dly_wait (20); 
      os_mut_wait(Mut_Test,0xffff); 
      os_mut_release(Mut_Test); 
      os_mut_wait(Mut_Test,0xffff); 
      os_mut_wait(Mut_Test,0xffff); 
      Test_Function(); 
   } 
}
Is it something natural or a bug ?
Thanks in advanced
 

I believe that the problem lies with the inherent definitions of a semaphore and a mutex. If you are using one task then we can assume that, besides the system idle task, that your "APP_TestTask" is the highest priority. Since a mutex incorporates priority inversion, and you also only have one task, the mutex will always fall to the "APP_TestTask". A semaphore, however, is causing problems since you are trying to both give away and take the semaphore from within a task; essentially, you are causing the task to stall.

I have never used a semaphore when I have just one task. Is there a specific reason for why you are doing this?

Regards,
Willis
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top