Open System Services Programmer's Guide

Example 72 Pthreads Nonblocking Disk File I/O (SPT_THREAD_AWARE_NONBLOCK version)
/*
* sptdio.c - SPThreads Diskfile IO Example Program
*
* This Pthreads program demonstrates a multithreaded program that
* can perform I/O on multiple OSS regular files (diskfiles) using
* non-blocking OSS I/O and Guardian nowaited I/O.
*
* Note that OSS I/O on regular files is serialized,
* even though the OSS non-blocking
* interface is used. This is standard Unix behavior.
*
* The following threads can be created by this program:
* - An OSS read thread which uses uses OSS I/O to completely
* read a regular file.
* - An OSS write thread which uses uses OSS I/O to write
* 1Mb of data to the regular file.
* - A Guardian read thread which uses Guardian nowait I/O to
* completely read a regular file.
* - A Guardian write thread which uses Guardian nowait I/O
* to write 1Mb of data to the regular file.
*
* USAGE SYNTAX:
*
* sptdio [-r <OSS-file>] [-w <OSS-file>] [-R <OSS-file>] [-W <OSS-file>]
*
* FLAGS
* -r <OSS-file> Create a thread that uses OSS I/O to
* completely read the given OSS diskfile.
* -w <OSS-file> Create a thread that uses OSS I/O to write the
* given OSS diskfile. 1Mb of data is written to the file.
* -R <OSS-file> Create a thread that uses Guardian nowait I/O to
* completely read the given OSS diskfile.
* -W <OSS-file> Create a thread that uses Guardian nowait I/O to write
* the given OSS diskfile. 1Mb of data is written to
* the file.
*
* EXAMPLE USAGE:
*
* /home/user: run sptdio -r /tmp/r1 -w /tmp/w1 -R /tmp/r2 -W /tmp/w2
*
* ==> All threads created...
* ==> OSS_write_thread() wrote 1048576 bytes to file /tmp/w1
* ==> OSS_read_thread() read 1581888 bytes from file /tmp/r1
* ==> Grd_WRITE_thread() wrote 1048576 bytes to file /tmp/w2
* ==> Grd_READ_thread() read 1581888 bytes from file /tmp/r2
*
* OSS BUILD INSTRUCTIONS:
*
* c89 sptdio.c -o sptdio -Wextensions -Wsystype=oss -g -D_XOPEN_SOURCE=1 \
* -lZSPTDLL
*/
#include <limits.h>
#include <stdlib.h>
/* Use the non-blocking version of the thread aware library */
#define SPT_THREAD_AWARE_NONBLOCK
#include <spthread.h>
#include <tal.h>
#include <cextdecs.h(CANCELREQ, FILE_CLOSE_, FILE_GETINFO_, FILE_OPEN_,
\ READX, WRITEX)>
350 Using the Standard POSIX Threads Library