Open System Services Programmer's Guide

Example 73 Pthreads Thread-Aware Disk File I/O Using SPT_THREAD_AWARE_XNONBLOCK
/*
* 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
* thread-aware OSS I/O functions available on systems running
* J06.04 and later J-series RVUs or H06.15 and later H-series RVUs.
*
* Note that OSS I/O on regular files is serialized.
*
* 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.
*
* USAGE SYNTAX:
*
* sptdio [-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.
*
* EXAMPLE USAGE:
*
* /home/user: run sptdio -r /tmp/r1 -w /tmp/w1
*
* ==> All threads created...
* ==> OSS_write_thread() wrote 1048576 bytes to file /tmp/w1
* ==> OSS_read_thread() read 1581888 bytes from file /tmp/r1
*
* 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 thread-aware library functions that are thread-aware
* (thread-blocking instead of process-blocking) for regular files
*/
#define SPT_THREAD_AWARE_XNONBLOCK
#include <spthread.h>
/********************/
/* LITERALS/DEFINES */
/********************/
/* the maximum number of I/O threads created by this program */
#define MAX_THREADS 4
/* concurreny level value passed to pthread_setconcurrency() */
/* the value of 100000 sets the minimum scheduled quantum to 0.000001 seconds. */
#define CONCURRENCY_LEVEL 100000
/* I/O size used by all threads */
#define IOSIZE 8192
/* size of files that are written - 1Mb */
#define WRITE_FILESIZE 1048576
360 Using the Standard POSIX Threads Library