Database record I/O and thread safety

The I/O feedback area of a database file can be used to communicate results of I/O operations to the record I/O user. A typical application might have problems with thread safety because of the nature of the feedback area.

When you perform an I/O operation, the support of the run time and of the database ensures that the I/O operation is threadsafe. When the I/O operation is completed, any locks that the run time holds are released and control is given back to the application.

It is the application's responsibility to serialize access when examining the I/O feedback area so that another thread does not use it simultaneously. COBOL and RPG use the feedback area on every I/O operation. Thus, if you perform I/O operations to the same shared file with different languages, you must serialize access to the file even if you are not apparently using the feedback area.

For example, Thread 1 uses file A for record I/O operations. The system stores information about those operations in the feedback area for file A. After the I/O operations for Thread 1 are completed, Thread 1 manipulates the feedback area by examining fields in the feedback area. If you do not protect the feedback area by serializing access to file A, Thread 2 might also use the same feedback area simultaneously when using file A for record I/O operations. As a result, Thread 1 can get inconsistent results because Thread 2 is using the feedback area at the same time. This situation occurs when sharing a file is conducted by using the file pointer or file descriptor number. It is not a problem if the file is opened in each thread.

You must use a synchronization technique to protect the feedback area from being changed by other application code or by the system when other application code or the system accesses the feedback area.