shared memory & link lists

Hello,

I’m trying to make a shared memory link list that can
be accessed ie: added or removed by 2 or 3 process.
Can this be done, if so how?

Tom.

Previously, tomf4 wrote in qdn.public.qnx4:

I’m trying to make a shared memory link list that can
be accessed ie: added or removed by 2 or 3 process.
Can this be done, if so how?

There are a few ways to create the shared memory, but
the most straightforward would be to use the shm_open()
and mmap() routines.

One way to have more than one process update the list,
is to have all processes that do this run at the same
priority using FIFO scheduling. This eliminates the
need to synchronize when going through critical pieces
of code.


Mitchell Schoenbrun --------- maschoen@pobox.com

tomf4 <tomf4@uniserve.com> wrote:

Hello,

I’m trying to make a shared memory link list that can
be accessed ie: added or removed by 2 or 3 process.
Can this be done, if so how?

Use shm_open() and mmap() to get the memory. Then, instead of each
next-ptr being a true ptr, make it, instead, an offset from the base
of the shared memory. Each process will get the memory mapped in at
a different address – but the relative offsets will always be the
same. Access will always be (base+offset).

The other option is to use the (undocumented) -@ option to cc to
specify that the base address of the program be moved to a higher
address, leaving room in low address space for the shared memory
to be mapped in at the same address in all the programs. (You
will need to specify appropriate options to mmap() to do this
as well.) Then you can use ordinary pointers. Be careful with
this option though, shared libraries (eg. Photon, X, TCP/IP)
under QNX4 are implemented this way, and if you are using any of
these libraries you don’t want to conflict with the offset they
are using. Also, with your -@ option you have to allow enough
space for the zero-page, the stack-guard page, and the maximum
stack size you have specified for the program.

-David