This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shared memory handling for mixed C/FORTRAN program

On Apr 12 13:23, Corinna Vinschen wrote:
> On Apr 11 20:25, Christoph Weise wrote:
> > Please see below, I provide minimal C code for three separate
> > executables, one creates the shm section, another finds it, the third
> > removes it. I include also a bash test script that executes the
> > routines in order.
> Thanks,
> > Please beware as I removed some checks to reduce
> > the length of the code, but it should run ok. The PAGESIZE parameter
> > is hardcoded (here 512 bytes). The desired shared mem section size is
> > set interactively as input to makeshm, or automatically with the bash
> > script. 
> Ok, but there are bugs in the code which result in GCC warnings.  I
> don't know which of them are part of your original code, but they are
> really a problem.
>   if ((int) -1 == p)
> Don't check a pointer against an int value.  It won't work on a 64 bit
> platform.  Make that
>   if ((void *) -1 == p)
> For the same reason, don't use %x to printf a pointer.  Use %tx.
> > I can write to the shm section with the second routine when the requested section <= 4096 bytes. Otherwise it's not happy. 
> The problem is the call to shmget:
>   #undef  PAGESIZE
>   #define PAGESIZE 512
>   shmid = shmget(key, PAGESIZE, IPC_ALLOC);
> Since you're requesting only 512 bytes, the shared memory segment the
> following shmat call returns is only 4K.  The shmget call should request
> as much memory as it needs so that the OS call is called with the right
> view size.
> I re-read the POSIX man page for shmget, and it doesn't mention anything
> which would point out that Cygwin's behaviour here is wrong.  If anybody
> has more information on this, please share them.

On second thought, adjusting Cygwin's behaviour to Linux here is rather
trivial.  I applied a patch to the git repo and uploaded new developer
snapshots (2015-04-12) to
You only have to replace the DLL itself, cygserver is not affected by
this patch.  Please give it a try.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpR_mWb2aEvQ.pgp
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]