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

> 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.

Yes, you're right. I tried a workaround that uses a second shm section to pass between executables either the size or more simply the shm ID of the main shm section. Either way this circumvented the problem.

However with this solution there is an odd change in the base address of the shm section between calls from the routine that creates the section to the executables that use it. I may be using the shm library inappropriately but my guess is that the OS/cygwin is doing something in the background (making a copy of the data?). Just for reference here's sample output:

$ $ ./test1.exe
storing in address 7fea0000 (7fea0000 + 0 floats):  0.000000
storing in address 7fea0fec (7fea0000 + 1019 floats):  1019.000000
storing in address 7fea0ff0 (7fea0000 + 1020 floats):  1020.000000
storing in address 7fea0ff4 (7fea0000 + 1021 floats):  1021.000000
storing in address 7fea0ff8 (7fea0000 + 1022 floats):  1022.000000
storing in address 7fea0ffc (7fea0000 + 1023 floats):  1023.000000
Detached from the shared memory section.
Attached at second address 7fea0000.
Message Queues:
T     ID               KEY        MODE       OWNER    GROUP

Shared Memory:
T     ID               KEY        MODE       OWNER    GROUP
m 1179648           3989570537 --rw-rw-rw-     John     John
m 131073           3989505001 --rw-rw-rw-     John     John

T     ID               KEY        MODE       OWNER    GROUP

-------------IN RUNME/FINDSHM----------------
Mapping the shared memory section ...
This is the key: -305396759.
size of section should be 4096.
Got this far (shmid : 131073).
Size of section: 4096.
Attached at address 7fe90000.
Checking memory pointers
pptr: 7fe90000
cptr: 7fe90200
cptr-pptr: 512
Check writing into the buffer at addresses starting at 7fe90000 + 4076 bytes (buffer size: 4096 bytes)
storing in address 7fe90000 (7fe90000 + 0 floats):  0.000000
content of address 7fe90fec (7fe90000 + 1019 floats):  1019.000000
storing in address 7fe90fec (7fe90000 + 1019 floats):  2038.000000
content of address 7fe90ff0 (7fe90000 + 1020 floats):  1020.000000
storing in address 7fe90ff0 (7fe90000 + 1020 floats):  2040.000000
content of address 7fe90ff4 (7fe90000 + 1021 floats):  1021.000000
storing in address 7fe90ff4 (7fe90000 + 1021 floats):  2042.000000
content of address 7fe90ff8 (7fe90000 + 1022 floats):  1022.000000
storing in address 7fe90ff8 (7fe90000 + 1022 floats):  2044.000000
content of address 7fe90ffc (7fe90000 + 1023 floats):  1023.000000
storing in address 7fe90ffc (7fe90000 + 1023 floats):  2046.000000

>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.

That did the trick. With the new cygwin1 DLL I don't need to pass shm section information between executables and the overall behavior is consistent with that on Linux.

Thank you for your help! I am very happy this works now on cygwin.

Problem reports:
Unsubscribe info:

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