Multi-threaded cursor fix using thread local variables