Open System Services Programmer's Guide

NOTE: When you use the #define SPT_THREAD_AWARE_XNONBLOCK or #define
SPT_THREAD_AWARE_PRAGMA_XNONBLOCK, if a function has a corresponding spt_*x() function
but not a corresponding spt_*z() function, the function is mapped to the corresponding
spt_*x() function.
The following example illustrates using the SPT_THREAD_AWARE_XNONBLOCK define:
#define SPT_THREAD_AWARE_XNONBLOCK
#include<spthread.h>
main()
...
For information about including a preprocessor directive in an application by specifying the directive
in a compiler command option, see the c89(1) or the c99(1) reference page online or in the
Open System Services Shell and Utilities Reference Manual.
Applications can explicitly call the functions listed in the rightmost column of Table 59 (page 344)
without setting any defines before including the spthread.h header file.
The spt_*z() Set of Functions Must Be Used Together
The Standard POSIX Threads library serializes I/O functions on open files only for the spt_*z()
set of functions. Therefore, if an spt_*z() function exists for a needed standard function, you
should use the spt_*z() function instead of using spt_*x(), spt_*(), or unmapped standard
functions directly.
For example, if you compile one module in a way that maps functions to corresponding functions
in the spt_*z() set of functions and you compile another module in a way that maps functions
to corresponding functions in the spt_*() or spt_*x() set of functions, you can get errors when
the two modules operate on the same open file:
1. Thread A calls spt_readz() 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 read() to read to the same open file MyDataFile, but the module was not
compiled using the SPT_THREAD_AWARE_XNONBLOCK preprocessor directive, so the call
to read() was automatically mapped to spt_read(). Because the spt_read() function
does not support serialization, spt_read() attempts to do the read and fails, returning the
error EALREADY. The EALREADY error indicates that an operation is already in progress.
In addition, using modules that were not compiled with any of the preprocessor directives with
modules that have been compiled using the SPT_THREAD_AWARE_XNONBLOCK or
SPT_THREAD_AWARE_PRAGMA_XNONBLOCK preprocessor directives can cause unexpected
results. For example, compiling a module so that it calls the unmapped standard function close()
directly, instead of the mapped function spt_closez(), might leave a thread with a pending
thread-aware regular file request suspended with no mechanism available to reschedule it for
execution.
Using Thread-Aware Functions
Example 69 (page 349) shows using thread-aware functions with a file stream. If the stream is to
be used with a nonblocking thread-aware function, it is not necessary to set the O_NONBLOCK
flag.
348 Using the Standard POSIX Threads Library