Please see my comment to the question. If does not make any sense, because the "problem" 1) is not a problem at all, 2) is not related to locking in any way.
Your
pFile
value is null, that's all. See what
openLogFile()
does, use the debugger. That's the solution.
As to the logging, it is used when some resource is shared between two or more threads. If you don't do it, you don't need locking. I have an impression that you don't have a clue what is it used for. You should not write a single line you don't perfectly understand. So, please read:
https://en.wikipedia.org/wiki/Mutual_exclusion[
^],
http://en.cppreference.com/w/cpp/thread/lock_guard[
^].
—SA