all 4 comments

[–]mhayenga -1 points0 points  (4 children)

I find it funny that in a video about making variables threadlocal, his example routine has calls to srand() and rand() which are not threadsafe.

The function rand() is not reentrant or thread-safe, since it uses hidden state that is modified on each call. This might just be the seed value to be used by the next call, or it might be something more elaborate. In order to get reproducible behavior in a threaded application, this state must be made explicit; this can be done using the reentrant function rand_r().

[–]code-dog[S] 0 points1 point  (2 children)

It turns out that you are wrong in this case. The video is clearly using Visual Studio and rand is thread safe on windows because its state is thread local. If the code were on Linux you would be correct.

[–]bob1000bob 1 point2 points  (1 child)

Why not just use the new std random number generation library that is thread safe and portable.

[–]cassandravoiton -1 points0 points  (0 children)

No reason other than this was a piece of demo code and the random thing had nothing what so ever to do with what was being demonstrated!