Re: How to read/write an 'address' from a memory location......



aeroboro221@xxxxxxxxxxxxxx wrote:

.... snip ...

My problem is: I have two processors exchanging data over a shared
section of memory. Now before processor 1 can write the data for
processor 2 (in the shared memory), processor 1 needs to tell
processor 2 where exactly it will be writing. Thats where i was
coming from - processor 1 basically needs to write an "address"
into a predefined location for processor 2 and that "address" will
hold the actual data for processor 2.

That is outside the abilities of the C language, which has no
intrinsic knowledge of multiple processes and managing them.
However, if your description is adequate, the following might work:

Global (common memory):
int running = 1;
Type *ptr = NULL;

Sender code fragment:
do {
/* prepare data */
while (ptr && running) continue;
if (running) {
ptr = malloc(sizeof *ptr);
*ptr = data;
}
} while (running)'

Receiver code fragment:
do {
while (!ptr && running) continue;
if (running) {
rcvdata = *ptr;
free(*ptr);
ptr = NULL;
/* process rcvdata */
}
} while (running);

Note that either process can shut down the interaction by setting
running to zero. Sender has a local variable named data, and
receiver has one named rcvdata. The processes are in strict sync,
i.e. one item of data causes one item to be transmitted, and
nothing more is done until that item is received. Similarly the
receiver can do nothing while waiting for new data to be prepared.

Note that malloc failing in sender is a fatal error. The
initialization values ensure that the sender runs first. The
definition of 'Type' controls the amount of data transferred. The
'continue' statements can be changed into function calls to do
other things.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: PostMessage and unprocessed messages
    ... The sender has no way to know when to delete the message, so making it the owner has no ... Since the receiver would have no way to know the message is deleted, ... collection, note that as long as something is in the queue, it is owned by the queue ... so adding memory management complexity to the ...
    (microsoft.public.vc.mfc)
  • Re: PostMessage and unprocessed messages
    ... No need to keep a linked list, because the PostMessage queue is already ... The sender has no way to know when to delete the message, ... Since the receiver would have no way to know the message is deleted, ... so adding memory management complexity to the ...
    (microsoft.public.vc.mfc)
  • Re: PostMessage and unprocessed messages
    ... No need to keep a linked list, because the PostMessage queue is already ... The sender has no way to know when to delete the message, ... Since the receiver would have no way to know the message is deleted, ... so adding memory management complexity to the ...
    (microsoft.public.vc.mfc)
  • Re: How to read/write an address from a memory location......
    ... section of memory. ... Type *ptr = NULL; ... Sender code fragment: ... receiver has one named rcvdata. ...
    (comp.arch.embedded)
  • Re: How to know the memory pointed by a ptr is freed?
    ... > contents of ptr and the memory pointed to by ptr after a call to ... It's undefined behavior, ... An address is an address, memory is memory, ... a reference to just the pointer value is ...
    (comp.lang.c)