Customized Lock/Unlock APIs

This tutorial assumes that you have gone through one of the three starter case tutorials and have successfully run Coderrect.

Mutex lock and unlock operations are frequently used to prevent data races. Coderrect recognizes standard and most commonly used lock/unlock operations (e.g., pthread_mutex_lock and std::lock). If the user’s code relies on customized APIs, Coderrect may not recognize them and hence may report false warnings.

To address the issue, Coderrect supports user-specified lock/unlock APIs through the configuration file .coderrect.json.

For example, adding the following to .coderrect.json will help Coderrect to recognize my_lock_api and my_unlock_api as a pair of lock and unlock APIs. Thus parallel data accesses protected by the pair of APIs will not be reported as data races.

//.coderrect.json
"lockUnlockFunctions": { 
    "my_lock_api" : "my_unlock_api"
}

You can add multiple pairs of lock/unlock APIs. For example, flash_lock and flash_unlock are another pair, and accel_lock2 and accel_unlock2 are another pair.

"lockUnlockFunctions": { 
    "my_lock_api" : "my_unlock_api",
     "flash_lock" : "flash_unlock",
     "accel_lock2" : "accel_unlock2"
}

Note that for each pair declared in lockUnlockFunctions, the order of the specified lock/unlock APIs are not interchangeable. That is, the specified pair has to start with the lock API and end with the corresponding unlock API.