Using Program Closures to Make an Application Programming Interface (Api) Implementation Thread Safe