Open System Services Programmer's Guide
Example 102 Using the Thread-Aware PUT_FILE_OPEN Function
/* Using the thread-aware PUT_FILE_OPEN function */
#define _PUT_MODEL_
#include <cextdecs.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h>
#include “myio.h” /* contains my_printf which is process blocking */
short filenum;
void *Thread2(void *args)
{
my_printf("Hello, I am Thread2\n");
}
void *Thread1(void *args)
{
short error;
char *name = "$SYSTEM.TEST.EX2";
my_printf("\nHello, I am in Thread1\n");
my_printf("Calling PUT_FILE_OPEN_ - thread-blocking Enscribe call \n");
error = PUT_FILE_OPEN_(name,(short)strlen(name),&filenum);
my_printf("error returned in open : %d filenum : %d\n",error,filenum);
error = FILE_CLOSE_(filenum);
my_printf("error in file close %d\n",error);
}
int main()
{
pthread_t T[2];
int ret_value;
int t = 1;
ret_value = pthread_create(&T[0],NULL,Thread1,(void *)t);
if (ret_value != 0)
{
my_printf("Error in creating the thread");
exit(1);
}
ret_value = pthread_create(&T[1],NULL,Thread2,(void *)t);
if (ret_value != 0)
{
my_printf("Error in creating the thread");
exit(1);
}
pthread_join(T[0],NULL);
pthread_join(T[1],NULL);
exit(0);
}
OSS File Descriptor and Timer Callbacks
Thread-aware functions listed in Table 73 allow registration and use of callbacks for OSS file
descriptors and timer callbacks. For details on each function, see the appropriate reference page
in the Open System Services System Calls Reference Manual.
422 Using the POSIX User Thread (PUT) Model Library