Calloc and Thread Safety
by DJ, on 4th August 2016
During my undergrad, I took a module on High Performance Computing which was taught in C and covered the usual suspects: MPI, OpenMP, CUDA etc. For each assignment, students uploaded their source code which was then automatically tested before being inspected by hand. The content was relatively straightforward, however when the 3rd assignment was returned to us, a number of students had been docked 25% of the mark with the comment:
calloc is NOT guaranteed to be thread safe.
Additionally the lecturer provided demonstration code to 'prove' the function wasn't thread safe on university machines. However, we hadn't had any problems when testing our code. What gives?