All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Semaphore Task
@ 2007-02-28  9:17 Preetam Joshi
  2007-02-28  9:30 ` Jan Kiszka
  2007-02-28  9:35 ` Dmitry Adamushko
  0 siblings, 2 replies; 3+ messages in thread
From: Preetam Joshi @ 2007-02-28  9:17 UTC (permalink / raw)
  To: xenomai-help

[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]

Hi i have a problem in my code the rt_sem_create calls returns a negative
value i.e. -17

THat is semaphore creation fails? Why is it so?

Here is the code that i am trying to execute. I have created semaphore in
the main routine.

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>

RT_TASK task1;
RT_TASK task2;

RT_SEM sem1;

int i,res;

void low_task(void *arg)
{

    printf("Inside the low priority task\n");
    rt_sem_p(&sem1,300000000);
    printf("I have the semaphore released by the high task\n");
}

void high_task(void *arg)
{

    printf("Inside the high priority task \n");
    res =rt_sem_p(&sem1,TM_INFINITE);
    printf("%d\n", res);
    if(res == 0)
    {
        printf("Semaphore Acquired by High task");
    }

    rt_task_sleep(3000000000);
    rt_sem_v(&sem1);
    printf("I have released the semaphore : High\n");
}

int  main()
{
    int res;

    mlockall(MCL_CURRENT|MCL_FUTURE);

        rt_task_create(&task2, "High Priority Task2", 0, 98, 0);
    rt_task_create(&task1, "Low Priority Task1", 0, 5, 0);

    res = rt_sem_create(&sem1, "Semaphore1", 0, S_PRIO);

    printf("%d\n",res);
    rt_task_start(&task2, &high_task, NULL);
        rt_task_start(&task1, &low_task,  NULL);

    pause();

    rt_task_join(&task1);
    rt_task_join(&task2);

}

[-- Attachment #2: Type: text/html, Size: 2258 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Semaphore Task
  2007-02-28  9:17 [Xenomai-help] Semaphore Task Preetam Joshi
@ 2007-02-28  9:30 ` Jan Kiszka
  2007-02-28  9:35 ` Dmitry Adamushko
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2007-02-28  9:30 UTC (permalink / raw)
  To: Preetam Joshi; +Cc: xenomai-help

[-- Attachment #1: Type: text/plain, Size: 373 bytes --]

Preetam Joshi wrote:
> Hi i have a problem in my code the rt_sem_create calls returns a negative
> value i.e. -17
> 

http://www.xenomai.org/index.php/Resolving_Error_Codes

> THat is semaphore creation fails? Why is it so?

Leftover registered name from a previous run? You are not cleaning up
the semaphore on termination. See /proc/xenomai/registry.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Semaphore Task
  2007-02-28  9:17 [Xenomai-help] Semaphore Task Preetam Joshi
  2007-02-28  9:30 ` Jan Kiszka
@ 2007-02-28  9:35 ` Dmitry Adamushko
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Adamushko @ 2007-02-28  9:35 UTC (permalink / raw)
  To: Preetam Joshi; +Cc: Xenomai help

On 28/02/07, Preetam Joshi <j.preetam@domain.hid> wrote:
> Hi i have a problem in my code the rt_sem_create calls returns a negative
> value i.e. -17
>
> THat is semaphore creation fails? Why is it so?

rt_sem_create()'s docs describe all the possible return values. -17 ==
-EEXIST (it's one of the possible errno values you may find in the
standard libc include files).

What probably happens in your case is as described below:

(look at the section for semaphores in /proc/xenomai/registry/)

-----------------------------------------------
> 1. On program start after previous crash i unable to create named mutex,
> because it [-EEXIST], after bind it's unable to operate with it because
> it locked by task from early died program, i have to restart computer.
> Any suggestions?

Something like this would do:

if (rt_mutex_bind("...", &desc) == 0)
       rt_mutex_delete(&desc);

rt_mutex_create("...", &desc);


-- 
Best regards,
Dmitry Adamushko


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-28  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-28  9:17 [Xenomai-help] Semaphore Task Preetam Joshi
2007-02-28  9:30 ` Jan Kiszka
2007-02-28  9:35 ` Dmitry Adamushko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.