I'm not sure that this is related to anything, but rand() is not thread safe.