Buffer Interprocess Sharing: Examples - C++

From RidgeRun Developer Wiki


Previous: Examples Index Next: Examples/Python






Introduction

The C++ examples take into account two possible cases:

  • One-to-one communication
  • One-to-many in broadcast communication

The example binaries are compiled after building. If the build directory is build:

├── src
    └── examples
        └── one-to-one
            ├── consumer
            └── producer

Executable options

Both executables have the same CLI options. Please, take them into account:

Usage:
	 consumer/producer [OPTION]...
Optional arguments:
	 -h, --help: Display this message and exit
	 --backend BACKEND: Use the specified inter-process shared memory
	                    backend; BACKEND can be 'shm' or 'nvsci'. Default: 'shm'
	 --channel CHANNEL: Connect to the specified shared memory channel.
	                    CHANNEL preferably starts with a '/' character
	                    followed by up to 255 characters, none of which
	                    are slashes. Default: channel
	 --num-buffers NUM_BUFFERS: Indicate how many shared memory buffers
	                            to create; NUM_BUFFERS can be a positive
	                            integer. Default: 10
	 --buffer-size BUFFER_SIZE: Indicate the size in bytes of a shared
	                            memory buffer; BUFFER_SIZE can be a
	                            positive integer. Default 33 MB
	 --exec-order ORDER: Follow execution order for buffer processing
	                     specified in ORDER; ORDER can be 'in-order' or
	                     'out-of-order'. Default 'in-order'
	 --process-size PROCESS_SIZE: Indicate the size in bytes of data to
	                              write to/read from shared memory
	                              during execution; PROCESS_SIZE can be
	                              a integer smaller than BUFFER_SIZE. Default:
                                      same as BUFFER_SIZE
	 --timeout TIMEOUT: Indicate how long to wait for available buffers
	                    before throwing a timeout error; TIMEOUT is
	                    measured in seconds and can be a positive
	                    integer. Default: 15 secs
	 --num-iterations NUM-ITERATIONS: Indicate how long many buffer
	                    processing iterations to run before exiting;
	                    NUM-ITERATIONS can be a positive integer. Default: 100
	 --logfile LOGFILE: Indicate name of file to log to. Default: consumer.log
                            or producer.log

You can use the defaults.

Running the examples

One-to-one example

1. Open two different terminals: one for the producer and another for the consumer.

2. In terminal 1, execute the producer:

./producer

3. In terminal 2, execute the consumer:

./consumer

One-to-many example

1. Open two different terminals: one for the producer and another for the consumer.

2. In terminal 1, execute the producer:

./producer

3. In terminal 2, execute two consumers:

./consumer --logfile consumer1.log & ./consumer --logfile consumer2.log

You can execute these two consumers in two different consoles as well.



Previous: Examples Index Next: Examples/Python