Open System Services Programmer's Guide
Example 93 Pthreads Thread-Aware Disk File I/O Using PUT Model Library
/*
* sptdio.c - Pthreads thread-aware 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
* Note that OSS I/O on regular files is serialized.
* Note: If you want process—blocking I/O behavior, export the
* PUT_THREAD_AWARE_REGULAR_IO_DISABLE = 1.
*
* The following threads can be created by this program:
* - An OSS read thread which uses OSS I/O to completely
* read a regular file.
* - An OSS write thread which 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 \
* -lZPUTDLL
*/
#define _PUT_MODEL_
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include “myio.h” /* contains my_printf which is process blocking */
/* Use the thread-aware library functions that are thread-aware */
/* (thread-blocking instead of process-blocking) for regular files */
#include <pthread.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
Thread-Aware and Nonblocking OSS Functions 401