Re: pipes
- From: moi <root@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Aug 2007 00:01:00 +0200
On Wed, 29 Aug 2007 12:39:48 -0700, CptDondo wrote:
Rainer Weikusat wrote:
On the client,
fd = open(somefile,O_RDONLY);
mmap(some block, PROT_READ....,fd)
fd = open(somefile, O_RDONLY);
p = mmap(NULL, length_of_data, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
Both 'client p' and 'server p' will point the same area of physical
memory from now on. 'msync' is only needed if you want to ensure that
changes are written to disk. You will need to come up with some sort
of 'access protocol' to ensure that the client doesn't read from the
same part of this area the server is currently writing to.
That's too easy... :-)
One last question about the "real time" aspect of this:
I only have one process that would write to this area. So if in the
server I set
p[0] = -1;
write ...
This "write" does not exist; at least the programs can't
detect whether is happened or not. The programs just "peek" into the same
diskbuffer. Whether that diskbuffer has been written to the disk or not is
irrelevant.
p[0] = 0;
then the client would know not to try to read the area until p[0] == 0.
Would this work? Or are the writes buffered somehow?
No. The only possible buffering is done by the compiler. This is what the
'volatile' keyword is all about. AFAIK, writes of machine-words are atomic.
Reads/writes to disks are atomic, too; (modulo pagesize). This can only be
violated by a hardware crash.
So, you are safe if there is a flag or pointer that is writable
by only the writer-process. (See also Lamport
http://research.microsoft.com/users/lamport/pubs/pubs.html#bakery
or http://research.microsoft.com/users/lamport/pubs/pubs.html#rd-wr )
HTH,
AvK
.
- Follow-Ups:
- References:
- Prev by Date: Re: putenv for AIX and ifdef for AIX
- Next by Date: Re: pipes
- Previous by thread: Re: pipes
- Next by thread: Re: pipes
- Index(es):
Relevant Pages
|