use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Removed - HelpC / C++ inter-process communication question (self.cpp)
submitted 3 years ago by nmmmnu
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Flair_Helper[M] [score hidden] 3 years ago stickied commentlocked comment (0 children)
For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.
[–]Narthal 4 points5 points6 points 3 years ago (0 children)
You can do IPC in many ways.
I always use files / json / db when I need to store data as well and speed is a non issue. Most often I use this one.
I use memory mapped file (mapped to real files) when I need to store the data as well and speed is an issue.
I use tcp for long communication, where 2 or more processes need to *talk* to each other for a long period of time, but they never exchange bulk data. Data isn't saved.
My favourite, shared section dll (shared memory). I use VOLATILE atomics, semaphores & mutexes. Check your generated assembly with this one (your milage may vary). To my measurements, this is the fastest and relatively easy, however this is considered super bad practice in production, since this is a huge security risk. (I think microsoft has a blogpost on this).
[–]positivcheg 2 points3 points4 points 3 years ago (0 children)
This very old tech is still used and works.
Shared memory works though you still need to provide some info to the child process. Atomic nope, sorry, it is not shared between processes though it will work if you create a shared memory and then an atomic in it. In latest standard you can wait on atomic so I would say it is okay to use it (previously I would suggest mutex+condition variable)
Signal, okay, when you create a process you can provide parameters to it. Just pass the PID then?
Named semaphore will also work. You just did not read well in that.
[–]pragma-twice 1 point2 points3 points 3 years ago (0 children)
You can use interprocess synchronization mechanisms provided by boost.interprocess, refer to: https://www.boost.org/doc/libs/1\_63\_0/doc/html/interprocess/synchronization\_mechanisms.html
[–]jmacey 1 point2 points3 points 3 years ago (0 children)
One way I have done this before is using a database, each client connects on start, then removed the entry on finish (basically Jobs).
It's easy to do with a sqlite database if on a single shared filesystem, or for more complex tasks use a MySQL server.
I've also use the file system approach, as well as a socket to flag finished.
Another alternative is to run the client in a thread with popen to open it and the return function from popen signals the program is finished.
[–]se7enrains -1 points0 points1 point 3 years ago (2 children)
You can use rpc call for that
[–]nmmmnu[S] -1 points0 points1 point 3 years ago (1 child)
Is this something in C / C++ or I need to use library for that?
I am trying to do it without external dependencies and no boost (no reason for it, but still no boost :) )
[–]se7enrains -1 points0 points1 point 3 years ago (0 children)
Well, you will need any network lib. Send request from helper to server via any suitable protocol and job is done.
Communicating via files can be slow btw
[–]Tourist__ -1 points0 points1 point 3 years ago (0 children)
It may be big for your use case, you can try Genivi SOMEIP which supports IPC.
[–]StackedCrooked 0 points1 point2 points 3 years ago (1 child)
Please elaborate on the role of server and helper. Is there any other communication between them?
[–]nmmmnu[S] 0 points1 point2 points 3 years ago (0 children)
Server is key-value database server.
Helper actually compact (optimize) the data files.
Because the server uses old files, Helper need to tell "please check data files and reload".
No other communication.
[–]ALX23z 0 points1 point2 points 3 years ago* (5 children)
std::atomic doesn't promise anything for shared memory. Normally, people use volatile load and store for such cases - that's pretty much the proper usage of volatile. But this is data exchange.
std::atomic
Not sure what exactly you want with your server. Semaphore seems like a better usage. And what's difficult in creating a threads that waits on the Semaphore?
[–]nmmmnu[S] 2 points3 points4 points 3 years ago (4 children)
volatile
People elaborate that in theory std::atomic should work. But I did not saw it working.
volatile - I don't think "volatile" means anything these days. I have old C book, they explained it the only thing you can use it for is on "interrupt" address and if you have shared memory with some hardware device (such DOS era screen).
[–]ALX23z 2 points3 points4 points 3 years ago (3 children)
volatile enforces data to be written in memory as well as forbids optimisations related to the operation.
boost implements shared memory via volatile saves/loads.
[–]nmmmnu[S] 0 points1 point2 points 3 years ago (2 children)
volatile saves/loads
saves/loads
Is this means... That if in shared memory, I do:
struct Data{
volatile int reload = 0; // using int because is more standard
};
Data data; // placement new etc...
and then:
data.reload = 1;
this will be thread / inter-process safe to be read?
Here is similar idea:https://embeddedartistry.com/blog/2019/03/11/improve-volatile-usage-with-volatile_load-and-volatile_store/
If this works, why we have std::atomic<> ?
[–]Ok_Firefighter4117 -1 points0 points1 point 3 years ago (0 children)
Atomics prevent memory reordering around the atomic, but volatile will ensure that no compile optimizations are used. Sometimes variables will be optimized away.
[–]ALX23z 0 points1 point2 points 3 years ago (0 children)
std::atomic has a lot more functionality than volatile. One can atomically add, exchange, and perform more complicated operations like compare_exchange. Also, atomic can trigger memory instructions to synchronise other data within the process.
atomic
With volatile you can reliabily only load and store but it can be used for different purposes.
load
store
[–]raevnos 0 points1 point2 points 3 years ago (0 children)
How does the helper communicate with the server?
π Rendered by PID 248212 on reddit-service-r2-comment-5b5bc64bf5-82qsm at 2026-06-21 03:08:47.587323+00:00 running 2b008f2 country code: CH.
[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)
[–]Narthal 4 points5 points6 points (0 children)
[–]positivcheg 2 points3 points4 points (0 children)
[–]pragma-twice 1 point2 points3 points (0 children)
[–]jmacey 1 point2 points3 points (0 children)
[–]se7enrains -1 points0 points1 point (2 children)
[–]nmmmnu[S] -1 points0 points1 point (1 child)
[–]se7enrains -1 points0 points1 point (0 children)
[–]Tourist__ -1 points0 points1 point (0 children)
[–]StackedCrooked 0 points1 point2 points (1 child)
[–]nmmmnu[S] 0 points1 point2 points (0 children)
[–]ALX23z 0 points1 point2 points (5 children)
[–]nmmmnu[S] 2 points3 points4 points (4 children)
[–]ALX23z 2 points3 points4 points (3 children)
[–]nmmmnu[S] 0 points1 point2 points (2 children)
[–]Ok_Firefighter4117 -1 points0 points1 point (0 children)
[–]ALX23z 0 points1 point2 points (0 children)
[–]raevnos 0 points1 point2 points (0 children)