Open System Services Programmer's Guide
int main(int argc, char *argv[])
{
/* the following variables correspond to the OSS filenames */
/* specified as command line parameters to the program */
char OSS_read_filename[PATH_MAX];
char OSS_write_filename[PATH_MAX];
/* total number of threads that have been created */
int nmbr_created_threads = 0;
/* array of handles for each thread created */
pthread_t thread_handle[MAX_THREADS];
int i;
/*************************************/
/* Process command line arguments */
/*************************************/
if (argc > 9)
{
my_printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>]\n");
exit(0);
}
/* verify that an even number of command line parameters */
/* was specified */
if (((argc - 1) % 2) == 1)
{
my_printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>]\n");
exit(0);
}
for (i = 1; i < argc; i = i + 2)
{
if (strcmp(argv[i], "-r") == 0)
{
strcpy(OSS_read_filename, argv[i+1]);
}
else if (strcmp(argv[i], "-w") == 0)
{
strcpy(OSS_write_filename, argv[i+1]);
}
else {
my_printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>]\n");
exit(0);
}
}
/**********************************/
/* Create all of the I/O threads */
/**********************************/
for (i = 1; i < argc; i = i + 2)
{
if (strcmp(argv[i], "-r") == 0)
{
pthread_create(&thread_handle[nmbr_created_threads++],
NULL, &OSS_read_thread, OSS_read_filename);
}
else if (strcmp(argv[i], "-w") == 0)
{
pthread_create(&thread_handle[nmbr_created_threads++],
NULL, &OSS_write_thread, OSS_write_filename);
}
}
my_printf("\n==> All threads created...\n");
Thread-Aware and Nonblocking OSS Functions 405