Inter-process communication library to enable allocation between processes/threads and send/receive of allocated regions between producers/consumer processes or threads using this ipc buffer.
This is a relatively simple IPC buffer that allows multiple processes
and threads to share a dynamic heap allocator, designate “channels”
between processes, and share that memory between producer/consumer
pairs on those channels.
Currently implemented is the following:
Currently testing the following combinations
/** only include file you should need **/
#include <buffer>
/**
* shared memory buffer allocated and returned as a pointer,
* this function can be called from each process safely to get
* the file descriptor opened and memory opened within your
* address space.
*/
auto *buffer = ipc::buffer::initialize( "thehandle" );
/** get a thread local data structure for the buffer with thread id **/
auto *tls_producer = ipc::buffer::get_tls_structure( buffer,
thread_id );
const auto channel_id = 1;
/**
* allocate a channel that is a single-producer, single consumer
* record channel, record channels are used for larger allocations
* up to 1MiB. The consumer must know that channel_id is the correct
* channel and also the type of channel otherwise an error will be
* thrown.
*/
ipc::buffer::add_spsc_lf_record_channel( tls_producer, channel_id )
/** get some memory and do something with it **/
int *output = (int*)
/** currently single allocations limited to 1MiB **/
ipc::buffer::allocate_record( tls_producer,
sizeof( int ),
channel_id );
/** lock-free record send **/
while( ipc::buffer::send_record( tls_producer,
channel_id,
(void**)&output )
!= ipc::tx_success );
//NOTE: consumer side has equiv lock-free receive record
/** close tls **/
ipc::buffer::close_tls_structure( tls_producer );
/** destroy the buffer **/
ipc::buffer::destruct( buffer /** buffer ptr **/,
"thehandle" /** file handle **/,
true /** unlink, true if you're the last user **/);
Currently only for Linux and OS X systems. Will add Windows
soon. Compiles with gcc 9+ and clang 10+.
git clone https://github.com/RaftLib/ipc.git
cd ipc
cmake ../
make -j
make test
Will add more notes soon. Most complete example with two
processes and two threads (1 process communicating with
another process that has two threads) is here