Previous Topic Next topic Print topic


Using the Program Thread-locking Routines

The following code at the entry to a program ensures that only the first thread entering a program will initialize data and all following threads will have that preinitialized data available:

if  first-time = 0
         call "cbl_thread_prog_lock"
        if  first-time = 0
             initialize my-data-division
            move 1 to first-time
        end-if
        call "cbl_thread_prog_unlock"
    end-if

Note the double check of the first-time variable. The first check is an optimization that avoids the overhead of locking the program if we know for sure that it has already been initialized.

Previous Topic Next topic Print topic