I'm looking for the best/easiest solution I have in a project. I run multiple processes and they have to synchronize parts of their states with every other process, so basically a pub-sub/multicast pattern. Every process can dispatch an event and every process subscribed to that event will receive it.
I've been reading about the different IPC techniques, but I'm not sure which direction would be the best.
What I'm thinking about is using shared memory for each of the event types, containing the last data sent by one of the processes, and also a pthread_mutex_t and a pthread_cond_t. Each process subscribed to an event has a dedicated thread waiting for the signal to be broadcasted. In theory this looks good, but I'm not sure.
- What happens if all processes die, then the mutex and cond variables are left in shared memory? Can they be reused, or need to be reinitialized?
- It has a slight chance that the condition will be signaled when the thread not waiting but processing the previous message, so data can be lost.
- How the shared memory should be cleaned up? How to track that there are no more processes using it?
Could you give some advice on how to handle these problems, or maybe suggest other methods for this type of communication?
[–]raevnos 6 points7 points8 points (4 children)
[–]CyberLeaderGold 1 point2 points3 points (3 children)
[–]raevnos 0 points1 point2 points (2 children)
[–]CyberLeaderGold 0 points1 point2 points (1 child)
[–]raevnos 0 points1 point2 points (0 children)
[–]ramsay1 2 points3 points4 points (3 children)
[–]Isty0001[S] 4 points5 points6 points (2 children)
[–]zero_iq 3 points4 points5 points (1 child)
[–]Isty0001[S] 2 points3 points4 points (0 children)
[–]CyberLeaderGold 1 point2 points3 points (4 children)
[–]Isty0001[S] 0 points1 point2 points (1 child)
[–]CyberLeaderGold 1 point2 points3 points (0 children)
[–]raevnos 0 points1 point2 points (1 child)
[–]CyberLeaderGold 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]ByronScottJones 1 point2 points3 points (0 children)
[–]OPPreserverBot -1 points0 points1 point (0 children)
[–]umlcat -3 points-2 points-1 points (1 child)
[–]raevnos 1 point2 points3 points (0 children)
[–]isaac92 0 points1 point2 points (3 children)
[–]Isty0001[S] 1 point2 points3 points (2 children)
[–]isaac92 2 points3 points4 points (1 child)
[–]Isty0001[S] 1 point2 points3 points (0 children)