Add API to exit thread