I have been converting an existing make based build system over to cmake, and overall I am loving it so far.<div><br></div><div>I happened to run across CheckForPthreads.c, and was a little surprised to see that it was basically a classic example of racy code.</div>
<div><br></div><div>The two spawned threads both increment res, which is then used as the return value of the whole program. So to prove to myself that this was a real issue, not just theoretical raciness, I compile the program, and ran it a couple million times on my linux box, and 7 of those two million runs returned 1 instead of 2. So the chance of screwup is quite small, but definitely non-zero.</div>
<div><br></div><div>Looking over the source I have a few questions:</div><div>Should it protect the increment with a mutex?</div><div>Or, should it really just spawn 1 thread? Is there a point to the spawning two?</div><div>
Is there a purpose to all the prints?</div><div>What is the line &quot;if(ac &gt; 1000){return *av[0];}&quot; there for? If it has a purpose that definitely deserves a comment.</div><div>What about the &quot;#if defined(__BEOS__)&quot;... lines? The usleep will only be there on BEOS, but the comment on the usleep line mentions sun.</div>
<div><br></div><div>Kevin</div>