A common error is to open() a file for writing before calling flock(). In that case, the file's contents are wiped by the open() before flock() checks if it's locked or not, by which time it's too late.
Of course, it's impossible to tell what your problem is without seeing any code.