Lionel Perrin wrote:
 > //   /* the following lines shouldn't be commented but xenomai... */
 > //   else
 > //   {
 > //           /* a new shm_file has been created, we need to truncate it */
 > //           if (ftruncate(h_shm, nbvalues * sizeof(double))==-1)
 > //           {
 > //                   printf("truncate failed\n");
 > //                   goto close_and_unlink;
 > //           }
 > //   }

Do you still have an issue with ftruncate ? 

Note that it is better to always call ftruncate even in a process that
is not creating the shared memory, this avoid the race condition where
the process that created the shared memory is about to truncate it and
is interrupted by the second process which did not create it but want to
mmap it.

 >      mem->h_mut = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 >      pthread_mutex_init(mem->h_mut, NULL);


Note that if you want to share the mem structure between several
processes, you should put the mutex on the shared memory, doing for
example:

typedef struct {
    pthread_mutex_t mutex;
    int nbaccess;
    double values[0]
} myshm_t;

myshm_t *myshm;

myshm = (myshm_t *) mmap(...);

mem->h_mut = &myshm->mutex;
mem->ptr = &myshm->values;

pthread_mutex_init(mem->h_mut, NULL);

Xenomai should detect that you are initializing a mutex that was already
initialized and return EBUSY that you can safely ignore.

-- 


                                            Gilles Chanteperdrix.

_______________________________________________
Xenomai-help mailing list
Xenomai-help@gna.org
https://mail.gna.org/listinfo/xenomai-help

Reply via email to