[M3devel] random-acces I/O

Mika Nystrom mika at async.caltech.edu
Sat Mar 1 23:49:23 CET 2008


Hi Hendrik,

The answer is, "it depends."  As a matter of fact this was my biggest
area of trouble when porting a program from PM3 on Unix to
PM3/Klagenfurt for NT386GNU.  On NT386GNU, the default is for
Modula-3 to avail itself of Windows's mandatory file locking, whereas
POSIX has no such thing.  This means that a Modula-3 program on
NT386GNU can't even open a file for reading if you are "lessing"
it for instance.  I am sure it can be worked around, but I never
bothered to figure out how, sorry (because the behavior I needed
was in fact strict locking of this kind, which I had to go to special
lengths to get on Unix!)

On Unix, things are a bit more as you describe them, but not exactly.
You can definitely have an Rd.T and a Wr.T on a single file, but I 
do not believe that the Rd.T and Wr.T will be aware of each other's
existence (I could be wrong).  However, there is a package called
rdwr(?) that I think may have the sort of functionality you're
looking for.  Maybe.

File locking is strictly an OS issue as far as I know and that is not
something that Rd and Wr concern themselves with.  

If you need this kind of low-level access I have a feeling Rd and Wr
are too high-level for you.  I would suspect you want to build something
with rdwr (or some other means of getting an Rd out of a Wr or vice 
versa) and then extend it with routines for maintaining a faithful
disk-based copy of what you want... using lower-level access methods.

Oh yes Rd and Wr are documented in detail in chapter 6 of the Green Book.

    Mika

hendrik at topoi.pooq.com writes:
>I need to do direct-access I/O from a Modula 3 program with a file 
>format that is externally specified.  It is necessary to both read and 
>write in random fashion during a run of the program, prefereably without 
>having to close or open the file each time.
>
>I expect the answers to the following questions are "Yes", but I'd 
>appreciate confirmation:
>
>  ? If I have a File.T (obtained from FS.OpenFile) can I have both a 
>    Rd.T and a Wr.T active on it simultaeously?
>
>  ? Will things written using the Wr.T be immediately available 
>    for reading with the Rd.T, with no buffereing problems?
>
>  ? Are there methods for locking the file -- or portions of it --  
>    against simutaneous access by other programs, including ones written 
>    in other languages?
>
>-- hendrik



More information about the M3devel mailing list