Open System Services Programmer's Guide
Serialization of File Operations On an Open File
The PUT Model library supports a thread-aware set of functions that serialize file operations on an
open regular file. If a thread calls one of the thread-aware functions to access a file that already
has a file operation in progress by a different thread, the calling thread is blocked until the prior
file operation is complete. For example:
1. Thread A calls the thread-aware version of the read() function to read the open file
MyDataFile. The file does not have an operation in progress, so thread A starts reading
the file.
2. Thread B calls the thread-aware version write() function to write to the same open file
MyDataFile. Because the read operation started by thread A is still in progress, thread B is
blocked and must wait for thread A’s read operation to complete.
Non-Regular Files
For non-regular files, there are functions that can provide thread-aware behavior or both nonblocking
and thread-aware behavior:
• The set of functions that are thread-aware are thread-aware whether or not the file descriptor
is nonblocking. If the O_NONBLOCK flag is set, these functions are also nonblocking: they
do not block the calling thread or the other threads, and they return one of these errors to the
application: EAGAIN, EINPROGRESS, or EWOULDBLOCK. Otherwise, these functions block
the calling thread but allow other threads to run. These functions remove the need for the
application to explicitly set the O_NONBLOCK flag of the file descriptor to enable thread-aware
behavior. The thread-aware functions are listed in the Nonblocking Thread-Aware Functions
(Non-Regular Files Only) column of Table 69 (page 398).
Equivalent System, Thread-Aware, and Nonblocking Thread-Aware Functions
The PUT model library does not provide analogs to spt_*x() or spt_*z()functions, such as
spt_readx() or spt_readz(), whose purpose is to be non-blocking alternatives to standard
system library functions. Instead, you refer to the standard function name and compile and link the
application as described in “Compiling and Linking Considerations” (page 380). Additionally, the
PUT model library does not provide analogs to spt_*() functions, such as spt_fprintf(),
whose purpose is to be non-blocking alternatives to the standard C run-time library functions.
Instead, you refer to the standard function names, which are thread aware for H06.21 and later
H-series RVUs and J06.10 and later J-series RVUs.
Table 69 lists standard functions that have equivalent thread-aware functions. For example:
• read() is a process-blocking function for both regular files and for non-regular files if you
are not using the PUT Model library.
• The PUT Model library version of read() is a thread-aware function with this behavior: For
non-regular files, this function does not require the file descriptor to be nonblocking for this
function to be thread-aware. If the file descriptor is nonblocking, this function does not block
the calling thread, and returns one of these errors to the application: EAGAIN, EINPROGRESS,
or EWOULDBLOCK. Otherwise, this function blocks the calling thread but allows other threads
to run. For regular files, this function blocks the calling thread but allows other threads to run.
This function does not require the file descriptor to be nonblocking for this function to be
thread-aware.
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 438)
Thread-Aware and Nonblocking OSS Functions 397