Patent Publication Number: US-5832265-A

Title: Reentrant libraries

Description:
This application is a 371 of PCT/DE93/00256 filed Mar. 22, 1993. 
     BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The method relates to the operation of computer installations having a number of processors and a joint memory. 
     2. Description of the Related Art 
     To utilize a number of processors with a shared memory, use is made of operating systems which can process a number of logical tasks simultaneously by providing a process control. In a known process control, the processes are largely isolated, thus in particular they use separate memory areas, assigned by the operating system. However, the degree of parallel work which can be achieved in this way is not adequate in practice. Either there are not an adequate number of processes ready for execution at the same time, meaning that processors are not utilized. Or, if the programs are divided further into processes, the benefit brought by parallel work is offset by the effort required for switching over and coordination of the processes. Therefore, an additional parallel control has been introduced, which is referred to as &#34;threads&#34; and allows a number of parallel execution paths within a process, these execution paths sharing all global variables and the program code. A description is given in chapter 6 (&#34;Programming with Threads&#34;) of the DCE Application Development Guide of the Open Software Foundation, Cambridge, USA, 1991. 
     The coordination of these execution paths is a task for the user, who uses for this a functional block of the thread components. This is a mechanism which is known as a semaphore and, in conjunction with threads, is referred to as a mutex. A mutex is a switch having an ON and an OFF state, to which a number of execution paths have access. A setting, i.e. switching over to the ON state, leads to a waiting state, if the switch is already in the ON state. The waiting state lasts until another execution path cancels the mutex again, i.e. the switch is brought back into the OFF state. Consequently, the protection of a program part which uses only a single operating means is possible. For this purpose, the mutex is set upon entry into this program part. It is consequently ensured that no other execution path uses this program part at the same time. At the end, the mutex is cancelled and consequently any waiting execution paths are given the possibility of then using the operating means exclusively. 
     If a threads component is subsequently added, the library subroutines made available to the user program and defined, for example, for the operating system UNIX in the System V Interface Definition are no longer compatible with the threads component. Therefore, shell subroutines are prepared under a new name, although the new name is similar to the old name for a human reader, and, before calling up the original library subroutine, these shell subroutines use a mutex in order to serialize these calls. This means, however, that the source code of the user program has to be altered, because the library subroutines have to be called up under a new name. 
     In addition, software producers are also supplying subsystems which are delivered in the form of subroutine libraries which for their part use the library subroutines of the operating system and are connected by a linking operation both to the user program and to the library subroutines. 
     SUMMARY OF THE INVENTION 
     The invention allows the original names to be retained and, nevertheless, the library subroutines to be serialized by mutex calls. 
     For this purpose, first of all, in a preparatory step, the library subroutines are investigated to ascertain whether they are compatible with threads. Incompatibility exists, for example, in the case of sequential file operations, because the operating system maintains a write and read pointer for each process and each file, but not for each thread. Included here are also the functions organized similarly to a file access for the receiving of messages or the acceptance of interrupt signals. Another case is when the result is provided in a static area of a subroutine and remains valid only until the next call; here, the next thread could overwrite the data which the previous thread has not finished evaluating. Both the file operations and the static areas are resources in the broad sense. 
     These incompatibilities which are thus determined serve for classifying the subroutines, subroutines from different classes being defined as those not having any joint thread-incompatible operating means. Consequently, each class can be assigned a dedicated inhibiting or exclusive means (MUTEX). This achieves a protective effect which is specific enough to achieve in the following step the effect that the user program then only uses protected library functions. If, specifically, only a single exclusive means is defined, the distributing effect of the threads over a number of processors is cancelled, because often only one thread is active and is waiting, for example, for a message. All the other threads then run only up until the time at which they call up a library subroutine. 
     After the preparations, now a protected copy of the library concerned can be produced. For this purpose, first, all the subroutines concerned are renamed, preferably to a name derived from the original name by a prefix such as &#34;O --  &#34;. Thus &#34;date&#34; becomes &#34;O --  date&#34;. This operation may be performed either on the sources of the library subroutines or by a program which modifies the library and the objects stored therein. Subsequently, the library is supplemented by shell subroutines. These first of all provide the original name (in the example &#34;date&#34;) and for their part call up the original library subroutine under the new name (in the example &#34;O --  date&#34;). In addition, before this call, a MUTEX is set via the threads component and is cancelled after this call. 
     The library which is thus created can be used instead of the original one by the user, who has a user program in the object format, and is nevertheless threads-compatible without any further measures. This necessity arises, as already mentioned, if on the one hand the user program uses subroutine libraries without having sources for them, but these for their part use the system libraries, such as in the case of a database component. Without the solution specified, the user program could not use the threads component. 
     An example of a main program, reduced to the maximum, reads as follows: 
     
         ______________________________________                                    
main( )                                                                   
char * date( );                                                           
char * result;                                                            
int year;                                                                 
result = date( );                                                         
sscanf(result, &#34;%d&#34;, &amp;year);                                              
printf(&#34;Year=19%d/n&#34;, year);                                              
}                                                                         
______________________________________                                    
 
    
     The corresponding shell procedure reads as follows: 
     
         ______________________________________                                    
char * date( )                                                            
mutex date.sub.-- mutex;                                                  
char * temp;                                                              
mutex.sub.-- on(date.sub.-- mutex);                                       
temp = O.sub.-- date( );                                                  
mutex.sub.-- off(date.sub.-- mutex);                                      
return temp;                                                              
}                                                                         
______________________________________                                    
 
    
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a schematic illustration of a main program call of a subroutine by two threads. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     The result is shown graphically in FIG. 1: a main program 10 uses the library 20. The control flow 11 is split into the two threads 12 and 13, which call up the subroutine &#34;date()&#34; at different times. By the linking operation, the shell subroutine 21 is consequently called up, first of all setting the mutex 23 and then calling up the original subroutine 22 by the call of &#34;O --  date()&#34;. After returning from this, the mutex 23 is cancelled and control returns to the thread 12 or 13 which was left. 
     Although other modifications and changes may be suggested by those skilled in the art, it is the intention of the inventor to embody within the patent warranted hereon all changes and modifications as reasonably and properly come within the scope of his contribution to the art.