www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - interprocess communication and sharing memory

reply "j55" <none none.com> writes:
This is my first attempt at a project in D, so pardon me if I'm 
overlooking something obvious:

I'm using libasync to create an eventloop, to set up something 
like a server/daemon process.  This part works very well.  We'll 
call this Server A.

Now I'd like to write another process (running on the same 
computer), we'll call Client B, and pass signals in to Server A.  
I want to be able to create the process independently from Server 
A, I don't want to have to spawn the process from the server.  
I'd also like to avoid creating a pipe process just to pass 
information from/to Server A and Client B.

What would be a good way to have Client B identify and pass 
signals and information to Server A (and back)? I would prefer to 
choose the fastest solution, as I hope to expand this to 
relatively large data sets.

After I get simple signal passing working, I'd like to attempt 
passing shared memory of c-style arrays with Plain Old Data types.

I've read many posts about shared memory and interprocess 
communication in D, but I didn't see any conclusive information 
about whether this type of interprocess memory sharing will be 
convenient or practical in D.  If it doesn't work out, I have 
some prototype already working in c++ with boost interprocess, 
but I'd prefer to use a native D solution if possible.
Sep 02 2015
next sibling parent reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Thursday, 3 September 2015 at 01:27:15 UTC, j55 wrote:
 This is my first attempt at a project in D, so pardon me if I'm 
 overlooking something obvious:

 I'm using libasync to create an eventloop, to set up something 
 like a server/daemon process.  This part works very well.  
 We'll call this Server A.

 Now I'd like to write another process (running on the same 
 computer), we'll call Client B, and pass signals in to Server 
 A.  I want to be able to create the process independently from 
 Server A, I don't want to have to spawn the process from the 
 server.  I'd also like to avoid creating a pipe process just to 
 pass information from/to Server A and Client B.

 What would be a good way to have Client B identify and pass 
 signals and information to Server A (and back)? I would prefer 
 to choose the fastest solution, as I hope to expand this to 
 relatively large data sets.

 After I get simple signal passing working, I'd like to attempt 
 passing shared memory of c-style arrays with Plain Old Data 
 types.

 I've read many posts about shared memory and interprocess 
 communication in D, but I didn't see any conclusive information 
 about whether this type of interprocess memory sharing will be 
 convenient or practical in D.  If it doesn't work out, I have 
 some prototype already working in c++ with boost interprocess, 
 but I'd prefer to use a native D solution if possible.
It's probably a stupid idea, but until someone with experience answers: what happens if you declare the memory as shared or __gshared and send a pointer to it via message passing or a pipe?
Sep 02 2015
next sibling parent "j55" <none none.com> writes:
On Thursday, 3 September 2015 at 02:52:00 UTC, Laeeth Isharc 
wrote:
 On Thursday, 3 September 2015 at 01:27:15 UTC, j55 wrote:
 [...]
It's probably a stupid idea, but until someone with experience answers: what happens if you declare the memory as shared or __gshared and send a pointer to it via message passing or a pipe?
I can give it a try tomorrow, for "message passing", which d library would you consider? I wasn't sure a simple pointer would work, I'd have to experiment. Though I'd like to try any safer higher level libraries for this, if they exist...
Sep 02 2015
prev sibling parent "thedeemon" <dlang thedeemon.com> writes:
On Thursday, 3 September 2015 at 02:52:00 UTC, Laeeth Isharc 
wrote:
 On Thursday, 3 September 2015 at 01:27:15 UTC, j55 wrote:
 This is my first attempt at a project in D, so pardon me if 
 I'm overlooking something obvious:

 I'm using libasync to create an eventloop, to set up something 
 like a server/daemon process.  This part works very well.  
 We'll call this Server A.

 Now I'd like to write another process (running on the same 
 computer), we'll call Client B, and pass signals in to Server 
 A.
 It's probably a stupid idea, but until someone with experience 
 answers: what happens if you declare the memory as shared or 
 __gshared and send a pointer to it via message passing or a 
 pipe?
Pointer from one process doesn't make any sense in another process, they point to different data in different address spaces, and most probably in the second process memory at this "address" isn't even allocated by the app, so it would be an access violation.
Sep 03 2015
prev sibling parent Justin Whear <justin economicmodeling.com> writes:
On Thu, 03 Sep 2015 01:27:14 +0000, j55 wrote:

 I've read many posts about shared memory and interprocess communication
 in D, but I didn't see any conclusive information about whether this
 type of interprocess memory sharing will be convenient or practical in
 D.  If it doesn't work out, I have some prototype already working in c++
 with boost interprocess, but I'd prefer to use a native D solution if
 possible.
I really like ZeroMQ for messaging--it scales transparently from IPC to TCP and packages lots of smart topologies for you. There's a D wrapper here: https://github.com/kyllingstad/zmqd For shared memory, it's pretty easy to do with std.mmfile.
Sep 03 2015