[CMake] CheckForPthreads.c

Kevin Fitch kfitch42 at gmail.com
Tue Jun 15 11:07:41 EDT 2010


I have been converting an existing make based build system over to cmake,
and overall I am loving it so far.

I happened to run across CheckForPthreads.c, and was a little surprised to
see that it was basically a classic example of racy code.

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.

Looking over the source I have a few questions:
Should it protect the increment with a mutex?
Or, should it really just spawn 1 thread? Is there a point to the spawning
two?
Is there a purpose to all the prints?
What is the line "if(ac > 1000){return *av[0];}" there for? If it has a
purpose that definitely deserves a comment.
What about the "#if defined(__BEOS__)"... lines? The usleep will only be
there on BEOS, but the comment on the usleep line mentions sun.

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100615/026180a4/attachment-0001.htm>


More information about the CMake mailing list