MVS files that are opened by data-set names or ddnames are thread-specific
in the following ways:
MVS files opened in update mode where repositioning functions are
used after the files have been extended are also restricted to the
owning thread. This is because a reposition might need to reopen
the read DCB in order to be able to see the new EOF marker. The runtime
library does not enforce this restriction.
Multivolume data sets, files that are part of a concatenated ddname,
and hiperspace memory files are further restricted in multithreaded
applications. All I/O operations are restricted to the thread on which
the file is opened.
When standard streams are directed to MVS files, they are governed
by the previous restrictions. Standard streams are directed to MVS
files in one of two ways:
- By default when a main() program
is run from the TSO ready prompt or by a JCL EXEC PGM= statement,
that is, whenever it is not initiated by the exec() function.
This is regardless of whether you are running with POSIX(ON) or POSIX(OFF).
In these cases, the owning thread is the initial processing thread
(IPT), the thread on which main() is executed.
- By explicit action when the user redirects the streams by using
command line redirection, fopen(), or freopen(). The
thread that is redirected (the IPT, if you are using command line
redirection) becomes the owning thread of the particular standard
stream. The usual MVS file thread affinity restrictions outlined above
apply until the end of program or until the stream is redirected to
the UNIX file system.
Any operation that violates these restrictions causes
SIGIOERR to
be raised and
errno to be set with the following
associated message:
EDC5024I: An attempt was made to close a file that had been
opened on another thread.
All MVS files opened from a given thread and still open when the
thread is terminated are closed automatically by the library during
thread termination.
Having more than one writer use separate file pointers to a single
data set or ddname is prohibited as always, regardless of whether
the file pointers are used from multiple threads or a single thread.
Note: These restrictions specifically do not apply to UNIX file
system. All opens and closes by the C library that result in calls
to an underlying access method for a given MVS file must occur on
the same thread. Therefore, the following specific functions are prohibited
from any thread except the owning thread (the one that does the initial
fopen()) of the file:
- fclose()
- freopen()
- rewind()