problem with qnx_segment_allocate_flags

Hi,

For a course I’m doing this semester I need to make a program which
allocates 32 kb of memory. This same program needs to manage the read and
read/write properties of this memory segment. I tried to do this using the
following:

base = qnx_segment_allocate_flags(32768, _PMR_MODIFY)

and after this setting the flags using:

qnx_segment_flags(base, _PMR_DATA_R+_PMR_MODIFY)

Now the memory is readonly and allocated just the way it’s supposed to be.
Then there is a wait sequence where the memory monitor just waits for a Send
action from a client. Then the monitor makes the segment read/write so the
client can put it’s information there:

qnx_segment_flags(base, _PMR_DATA_RW+_PMR_MODIFY);

(now it sends the base adress to the client so it can begin writing)

This works fine and after the writing is completed the client sends a
message to the monitor. The monitor calls
qnx_segment_flags(base,_PMR_DATA_R+_PMR_MODIFY).

But when the same client tries to write again the segment doesn’t seem to be
blocked. So my question is (the source is currently unavailable :/) how can
I adjust my code in such a way that every client has only the right for one
write action? Is this a limitation of QNX? or am I missing something here?


TIA,
Frostie

i’ll take a look.

just as a side note though…

  • you really mean _PMF right?
  • segments are really ugly… can you do the same operation with shm_open and
    mmap? i would recommend that approach much more highly and it is more
    portable too.

with segments there are a lot of gotchas… the biggest is that you should
avoid sharing your segment with get/put calls if you have a dynamic
dataspace… in other words, don’t grow your ds with malloc after you
‘put’ your ds (i am assuming that ‘base’ is pointing to your own ds.

would you be willing to look at the mmap routines instead? (please please
please)


Frostie <frustie@dds.nl> wrote:

Hi,

For a course I’m doing this semester I need to make a program which
allocates 32 kb of memory. This same program needs to manage the read and
read/write properties of this memory segment. I tried to do this using the
following:

base = qnx_segment_allocate_flags(32768, _PMR_MODIFY)

and after this setting the flags using:

qnx_segment_flags(base, _PMR_DATA_R+_PMR_MODIFY)

Now the memory is readonly and allocated just the way it’s supposed to be.
Then there is a wait sequence where the memory monitor just waits for a Send
action from a client. Then the monitor makes the segment read/write so the
client can put it’s information there:

qnx_segment_flags(base, _PMR_DATA_RW+_PMR_MODIFY);

(now it sends the base adress to the client so it can begin writing)

This works fine and after the writing is completed the client sends a
message to the monitor. The monitor calls
qnx_segment_flags(base,_PMR_DATA_R+_PMR_MODIFY).

But when the same client tries to write again the segment doesn’t seem to be
blocked. So my question is (the source is currently unavailable :/) how can
I adjust my code in such a way that every client has only the right for one
write action? Is this a limitation of QNX? or am I missing something here?



TIA,
Frostie






Randy Martin randy@qnx.com
Manager of FAE Group, North America
QNX Software Systems www.qnx.com
175 Terence Matthews Crescent, Kanata, Ontario, Canada K2M 1W8
Tel: 613-591-0931 Fax: 613-591-3579