Add thread cleanup to avoid double destruction of shared XS data