Skip to content

Guidelines for Thread-safe Programs

The -fthread-safe compiler flag causes thread-safe code to be generated.

Take care to use the -fthread-safe compiler flag when interoperating with Java. All programs in an application that interoperates with Java should be compiled with -fthread-safe, even those not directly calling, or called by Java. For more information on Interoperability between COBOL-IT and Java, see COBOL/Java Interoperability.

Thread safe internal structures now use the pthread library, which is available in AIX, Linux, HPUX Itanium, Sun Solaris and Windows operating environments.

Thread memory release and support for a program monitor

COBOL-IT supports Thread memory release and support for a program monitor taking control of the abort & exit of the COBOL-IT runtime. A typical "program monitor" should use the following scheme to call COBOL programs:

       /* Allocate Runtime Data memory for this thread */ 
       cit_runtime_t * constrtd = cob_get_rtd(); 

       int (*func)(); 
       int res; 

       /*initialize COBOL Thread runtime */ 
       cob_init(rtd, argc, argv); 

       /* Prepare the Runtime to exit with a long jump instead of exit(x)*/ 
       res = cob_setjmp(rtd); 
       if ( res == 0) { 
              /* Find the COBOL Program */ 
              func = cob_resolve(rtd, "prog"); 
              if ( func ) { 
                     /* Call it and all other needed*/ 
                     func(); 
              } 
              /* if the Program goes Here the the COBOL exit normally 
              */ /* with a GO BACK                      */ 
              
       } else if ( res > 0 && res < 127) { 
              /* COBOL Program exit normally through STOP RUN */ 
              /* res hold the RETURN-CODE */ 
               

       } else { 
              /* COBOL Program exit on runtime abort */ 
              /* res hold the error code */ 
               

       } 
       /* Before leaving the Thread Release Runtime Data */ 
       cob_rtd_tidy ();
Back to top