Open System Services Programmer's Guide
Example 83 Using the Thread-Aware SPT_FILE_OPEN Function
/* Using the thread-aware SPT_FILE_OPEN function */
#include <cextdecs.h>
#include <spthread.h>
#include <stdio.h>
#include <string.h>
#include <tal.h>
short filenum;
void *Thread2(void *args)
{
 printf("Hello, I am Thread2\n");
}
void *Thread1(void *args)
{
 short error;
 char *name = "$SYSTEM.TEST.EX2";
 printf("\nHello, I am in Thread1\n");
 printf("Calling SPT_FILE_OPEN_ - thread-blocking Enscribe call \n");
 error = SPT_FILE_OPEN_(name,(short)strlen(name),&filenum);
 printf("error returned in open : %d filenum : %d\n",error,filenum);
 error = FILE_CLOSE_(filenum);
 printf("error in file close %d\n",error);
}
void main()
{
 pthread_t T[2];
 int ret_value;
 int t = 1;
 ret_value = pthread_create(&T[0],NULL,(void *)Thread1,(void *)t);
 if (ret_value != 0)
 {
 printf("Error in creating the thread");
 exit(1);
 }
 ret_value = pthread_create(&T[1],NULL,(void *)Thread2,(void *)t);
 if (ret_value != 0)
 {
 printf("Error in creating the thread");
 exit(1);
 }
 pthread_join(T[0],NULL);
 pthread_join(T[1],NULL);
 exit(0);
}
378 Using the Standard POSIX Threads Library










