What’s the point of the variable a
here? I can barely understand this code. Do you have a single-threaded version that works? Could you post that (or a shorter version of it)?
Also note that rand()
is not thread safe. See my recent post and suggested workaround here.