HP Pascal/HP-UX Release Notes Version A.10.08

32 Chapter 1
New and Changed Features
Making Thread-Safe HP Pascal/HP-UX Routines
Input/Output
Because of the language definition of various Pascal I/O statements, it is
impossible to make them completely thread-safe. For example,
WRITELN(f,a,b,c);
is replaced by
WRITE(f,a); WRITE(f,b); WRITE(f,c); WRITELN(f);
and
READDIR(f,k,x);
is replaced by
SEEK(f,k); READ(f,x);
In a threaded application, the input or output could be interspersed.
Because of the language design limitation, you must do your own locking
for each file or use a separate file for each thread.
NOTE The Pascal Runtime Library assumes that you are coordinating your I/O
to files. It does NO locking whatsoever. If you fail to do this, the result
could be interspersed output, or worse.
There is another class of routines that are inherently unsafe, since the
values that they return may be invalid as soon as they are returned. This
class includes EOF, EOLN, LASTPOS, LINEPOS, and MAXPOS. These
routines and the GET and PUT routines may require locking around
multiple I/O statements or where the buffer variable f^ is referenced.
File Control Block List
The only limited locking that the library does is to protect the global
linked-list of Pascal file control blocks. Opening or closing a file adds to or
deletes from this list. The Pascal I/O module maintains this list so that
files can be closed on routine exit, heap deallocation, or nonlocal GOTO
and ESCAPE. Because the compiler does this implicitly, these operations
were made thread-safe.