On Tue, 2003-07-15 at 11:39, Juhana Sadeharju wrote:
I would like to test with posix routines as well.
Can you mail me some example code? Plain ascii, no attachments.
If I would have a list of posix shm routines, I would read the
man pages, but then I did read systemv man pages as well, and that
did not help at all. :) Example code would be nice.
IEEE/POSIX 1003.1-2001 standard documentation is readable at the web.
http://www.opengroup.org/onlinepubs/007904975/
Also at least RedHat 9 contains the documentation as manpages.
Basically you do:
1) shm_open() (or creat()/open() some tmp file if shm_open() is not
available).
2) ftruncate() to some size
3) mmap() single or various regions of it (note that if offset != 0 the
address has to be page aligned (see sysconf()))
4) do some stuff, you should have reference counting contained to be
able to destruct the shared memory when the last one goes off
5) munmap() & close() & shm_unlink() (or just unlink())
See also msync(). Note that if you have SMP then you may need some
barrier stuff to flush dcaches (unless write through).
Now I usually do two mmap()s, first for header containing reference
count and locking stuff and second for the data, thus the header stuff
is protected from the data.
See also pthread PSHARED flag, which seems to be supported in NPTL
(included in RH9) but not supported under old LinuxThreads. Works also
under Solaris 8/9.
--
Jussi Laako <jussi.laako(a)pp.inet.fi>