Open System Services Programmer's Guide

Example 106 Threaded Time-of-Day Server Socket Using $RECEIVE
#define _PUT_MODEL_
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
#include <cextdecs.h(FILE_OPEN_,READX,FILE_CLOSE_,WRITEX,FILE_GETINFO_)>
#include <cextdecs.h(FILE_GETRECEIVEINFO_)>
#include <cextdecs.h(REPLYX)>
#include <cextdecs.h(READUPDATEX)>
#include myio.h /** contains my_printf which is process-blocking**/
/*
Must come after cextdecs.h:
*/
#include <pthread.h>
void * server_thread(void* target)
{
char buffer[1024];
time_t now;
int error;
time(&now);
strcpy(buffer, ctime(&now));
/*
A compiler warning will occur regarding the next line, which is OK:
*/
error = put_REPLYX(buffer, (short) strlen(buffer), NULL,
(short)target, 0);
my_fprintf(stderr,"server_thread: put_REPLYX: error: %d\n",error);
fflush(stderr);
return NULL;
}
int main(void)
{
pthread_t my_thread;
pthread_attr_t my_attr;
char *filename = "$RECEIVE";
char buffer[1024];
long bytesread, error;
short receive_info[17];
short dialog_info;
short target;
short filenum;
/*
Sets concurency level:
*/
if(pthread_setconcurrency(1))
{
perror("pthread_setconcurency");
exit(-1);
}
/*
Initializes attribute:
*/
if(pthread_attr_init(&my_attr))
{
perror("pthread_attr_init");
exit(-1);
}
436 Using the POSIX User Thread (PUT) Model Library