All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Lionel Perrin <perrin@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] shm_open, ftruncate
Date: Fri, 9 Jun 2006 14:28:38 +0200	[thread overview]
Message-ID: <17545.26998.683843.924195@domain.hid> (raw)
In-Reply-To: <448937A5.7080701@domain.hid>

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.


  parent reply	other threads:[~2006-06-09 12:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-02 15:29 [Xenomai-help] shm_open, ftruncate Lionel Perrin
2006-06-02 16:29 ` Gilles Chanteperdrix
2006-06-02 17:17 ` Gilles Chanteperdrix
2006-06-05 13:49   ` Lionel Perrin
2006-06-05 15:55     ` Gilles Chanteperdrix
2006-06-06 11:53       ` Lionel Perrin
2006-06-06 12:21         ` Gilles Chanteperdrix
     [not found]           ` <44859C28.3090600@domain.hid>
     [not found]             ` <17541.49945.431732.834139@domain.hid>
2006-06-07 12:55               ` Lionel Perrin
2006-06-07 14:52                 ` Gilles Chanteperdrix
2006-06-09  8:56                   ` Lionel Perrin
2006-06-09 11:46                     ` Gilles Chanteperdrix
2006-06-09 12:28                     ` Gilles Chanteperdrix [this message]
2006-06-09 13:18                       ` Lionel Perrin
2006-06-06 18:08         ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17545.26998.683843.924195@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=perrin@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.