Skip to contentSkip to conversation

Semaphore creation problem in user-space

Xenomai-help MEYLAN Jean-philippe 2 participants 2 messages Oct 9, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to make a Xenomai target for Mathwork's Real Time Workshop Embedded Coder and I need to embed the generated code in an user-space application. My problem is that I cannot create semaphores correctly. rt_sem_create() returns me the -17 value instead of 0 or one of the error codes described in the documentation. I cannot figure what is the cause of the problem.

This problem appears in the small code I've put in attachment.

Have you any idea of what I'm doing wrong ?

Thanks in advance for your reply.

Best regards,

Jean-Philippe

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

#define STACK_SIZE 8192

RT_TASK test_task_ptr;
RT_SEM semaDesc;

void clean_exit(int dummy) {
	printf("cleanup\n");
	rt_sem_delete(&semaDesc);
}

int main(int argc, char *argv[]) {
int err, ret;

  printf("start\n");
  signal(SIGTERM, clean_exit);	
  signal(SIGINT, clean_exit);	

  mlockall(MCL_CURRENT | MCL_FUTURE);

  err = rt_sem_create(&semaDesc, "sema", 0, S_FIFO);
  if (err) {
     printf("error sema : %d\n",err);
  }

pause();
fflush(NULL);
return 0;
}

#1 lore raw
Quoted 9 lines · MEYLAN Jean-philippe

Hi,

I'm trying to make a Xenomai target for Mathwork's Real Time Workshop Embedded Coder and I need to embed the generated code in an user-space application. My problem is that I cannot create semaphores correctly. rt_sem_create() returns me the -17 value instead of 0 or one of the error codes described in the documentation. I cannot figure what is the cause of the problem.

Quoted 3 lines

This problem appears in the small code I've put in attachment.

Have you any idea of what I'm doing wrong ?

-17 is -EEXIST. We use (negative) standard POSIX code to report all error statuses (i.e. see asm-generic/errno-base.h).

Your sema4 has already been registered. Either your app mis-generates semaphore names, or you more likely restarted the application which tried to register the same semaphores anew, with a pre-2.4 Xenomai version. i.e. Xenomai automatically removes real-time objects created by exited applications only since 2.4-rc1.

A quick hack to work around the auto-cleanup issue with 2.3.x is to use a pattern like this:

	RT_SEM desc;

	if (rt_bind_sem(&desc, some_name, TM_NONBLOCK) == 0) {
	    rt_delete_sem(&desc);

	err = rt_sem_create(&desc, some_name, ...)

Not pretty, but works.

Quoted 12 lines

Thanks in advance for your reply.

Best regards,

Jean-Philippe

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.