Binary Semaphore Problems

Joel Sherrill joel.sherrill at OARcorp.com
Wed Dec 3 17:03:32 UTC 2003


James Yates wrote:

> I am currently testing my port of RTEMS and have managed to get multiple tasks running. I start looking at 
> semaphores and have a small piece of test code with a binary semaphore blocking access to a register. 
> When I create the semaphore RTEMS_SUCCESSFUL is returned and I am given a semaphore id. But when
> either of my tasks tries to obtain this semaphore, RTEMS_UNVALID_ID is returned, but I can't figure out
> why. Does anyone have any ideas? 

Is the static variable sem_id declared global or in the scope of the
create?  Remember thread == C function so visibility could be an issue.
Two static variables of the same name in different functions are
different physical variables.

If the variable is static "global" and thus visible by both threads,
then my assumption is that it is being overwritten between the two
calls.  Add a printf and see what the ID is at create time and on error.

> 
> I create the semaphore using:
> 
> static rtems_id        sem_id;
> 
>   status = rtems_semaphore_create(rtems_build_name( 'S', 'E', 'M', '1' ), 1, 
>               RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|
>                                     RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
>                 0,
>                 &sem_id);
> 
> Then in the task:
> 
>     status2 = rtems_semaphore_obtain(sem_id, RTEMS_WAIT, 0);
>     PDDR ^=0x0800; 
>     rtems_task_wake_after(500);
>     PDDR ^=0x0800; 
>      status2 = rtems_semaphore_release(sem_id);


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the users mailing list