Open System Services Programmer's Guide

{
perror("pthread_attr_init");
exit(-1);
}
/*
Sets detach state for thread attribute:
*/
if(pthread_attr_setdetachstate(&my_attr,PTHREAD_CREATE_DETACHED)!=0)
{
perror("pthread_attr_setdetachstate");
exit(-1);
}
error = FILE_OPEN_(filename, (short)strlen(filename), &filenum,
0, , 1, 10, 1);
fprintf(stderr,"main: FILE_OPEN_: error: %d\n",error);
assert(error == 0);
error = spt_INITRECEIVE(filenum, 10);
fprintf(stderr,"main: spt_initReceive: error: %d\n",error);
fflush(stderr);
assert(error == 0);
while (1)
{
error = spt_RECEIVEREAD(filenum, buffer, (short)sizeof(buffer),
&bytesread, -1, receive_info, &dialog_info);
fprintf(stderr,"main_thread: spt_RECEIVEREAD: error: %d\n",error);
target = receive_info[2];
if(pthread_create(&my_thread, &my_attr, &server_thread, 0
(void *)target))
{
perror("pthread_create");
exit(-1);
}
} /* while */
} /* main */
Thread-Aware and Nonblocking OSS Functions
If a function must wait for an I/O operation to complete, the function blocks its caller (either a
thread or a process) from continuing until the I/O operation completes. A function that blocks all
threads while it waits for I/O to complete is a process-blocking function. Process-blocking functions
are not thread aware. If a thread calls a process-blocking function, the calling thread and all the
other threads in the process are prevented from continuing until the I/O operation is complete and
the function returns a status indication. Standard OSS I/O library functions are not thread-aware.
In contrast to a process-blocking function, a thread-aware function blocks only the thread calling
that function, instead of blocking all threads in the process. The other threads in the process can
continue doing work while the calling thread waits for I/O to complete. A thread-aware function
is sometimes called a thread-blocking function, because it blocks only the calling thread.
Sometimes it is not enough for a function to be thread-aware. There can be times when you do not
want even the calling thread to wait for I/O to complete. Instead, you want the function to either
succeed immediately or to fail immediately. Functions that do not block the calling thread or the
340 Using the Standard POSIX Threads Library