I think xoring the threadID here needs a comment, it's a bit hard to tell what's going on.