Open System Services Programmer's Guide

/*******************************************************************/
/* NOTE that this code does not execute for regular (disk) files, */
/* because write() on a regular file never returns EWOULDBLOCK or */
/* EAGAIN */
/*******************************************************************/
ret = spt_fd_write_ready(fd, NULL);
if (ret != 0)
{
printf("*** ERROR in OSS_write_thread:
spt_fd_write_ready()failed w/error %d ***\n", ret);
exit(0);
}
}
else
{
printf("*** ERROR in OSS_write_thread:
write() failed w/error %d ***\n", errno);
exit(0);
}
}
else /* write successful */
{
currsize += nbytes;
/*****************************************************************/
/* When doing Non-Blocking OSS I/O to diskfiles, it is a good */
/* idea to call sched_yield(), otherwise this thread won't give */
/* up control until the file is completely written. This is */
/* because write() never returns EWOULDBLOCK for a diskfile. */
/*****************************************************************/
sched_yield();
}
} /* while */
close(fd);
printf("==> OSS_write_thread() wrote %d bytes to file %s\n",
WRITE_FILESIZE, OSS_write_file);
return(NULL);
}
/* Grd_READ_thread --
*
* Description:
*
* This thread reads an OSS file using Guardian Nowait I/O.
*
* This function performs Guardian nowait I/O in a thread aware
* manner, such that the entire program never blocks.
* Note however that this thread blocks when it waits for I/O
* completions.
* Other threads are free to do work while this thread is blocked
* waiting for an I/O completion.
*
* Since Guardian nowait I/O is not serialized, this program can
* have multiple outstanding Guardian I/O requests.
*
* Results:
* none.
*
*--------------------------------------------------------------------
*/
void *Grd_READ_thread(void *Grd_READ_file)
{
short fnum;
long count_read;
354 Using the Standard POSIX Threads Library