This is using shared memory in Rust, in a container.
Build with Cargo:
cargo buildRun the application:
cargo runOptions
struct- will use a struct to store two single charactersarray- will use an array to store two integersisinit- will show if the shared memory is initialized or not
cargo run -- structThen run another one and see how the communicate.
Another option is to run the first one, and, within 5 seconds run the second one:
cargo run -- isinitIt will fail, as it waits for only one second, and there is a delay of 5 seconds to simulate a real delay in startup. If you run it again after the first process is initialized it will succeed and and show that the shared memory is initialized.
Note: The docker-compose.yaml file is not supposed to run, it is only an example on docker run params and it useful when building.
Build the container image:
docker compose buildRun the container:
#leader
docker run --rm -ti --ipc=shareable --name=pocshm_leader pocshm
# follower
docker run --rm -ti --ipc=container:pocshm_leader --name=pocshm_followerCheck if the shared memory is initialized:
# checking on the leader
docker exec -t pocshm_leader /pocshm isinit
# or checking from another container
docker run --rm -ti --ipc=container:pocshm_leader pocshm isinitLicensed under the MIT license.