delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/04/13/07:00:34

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:to:message-id:in-reply-to
:references:subject:mime-version:content-type
:content-transfer-encoding; q=dns; s=default; b=iAidLCmZFnFspv/J
BxrYuN/vlkD9eieOjrV3BeMXIcDY+IhT9h+9jqnfmg3CuWJZM8goKKHZSNd6zrhJ
jEw4rDTsrfUJiIM+JSEuhQznUW/IhG+LjZbAt7yr7kSiMfSa0md+Qf7msLyWxAS3
iQCxyF5dNf1A++Hcy42fmAFsJWw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:to:message-id:in-reply-to
:references:subject:mime-version:content-type
:content-transfer-encoding; s=default; bh=1FRxm2D7H1q1NN8K5DZJhW
dCRX0=; b=hCxUA/hDbqOhHmaVSkweXfpkzirRtZUoNfNyxbTMLZqDwLy4x+qpVI
BILhDkaZUt5tQ3h+3wbYd34M5rTd9ccdQNZ7E4Sq9+rlfHnmTFlKKHgLezDTZiK6
knqAbDB5tfYineHU/4SVN2T7OCQw1t9fzO7zg0e8WwvEoHBigCCYA=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.4 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2
X-HELO: nm41-vm8.bullet.mail.bf1.yahoo.com
Date: Mon, 13 Apr 2015 11:00:07 +0000 (UTC)
From: Christoph Weise <cfweise AT yahoo DOT com>
Reply-To: Christoph Weise <cfweise AT yahoo DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Message-ID: <1870355684.2072453.1428922807636.JavaMail.yahoo@mail.yahoo.com>
In-Reply-To: <1999567694.2259208.1428493743005.JavaMail.yahoo@mail.yahoo.com>
References: <1999567694 DOT 2259208 DOT 1428493743005 DOT JavaMail DOT yahoo AT mail DOT yahoo DOT com>
Subject: Re: Shared memory handling for mixed C/FORTRAN program
MIME-Version: 1.0


> 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

Semaphores:
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 https://cygwin.com/snapshots/
>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:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019