Author: Andrew FalangaAndrew Falanga
Date: Jan 15, 2008 08:54
Hi,
I'm working through a problem that I've just stumbled across with a
multi-threaded program I'm writing. This program has a logging
facility which is maintained through a Log class/object. This object
gets instantiated in main() and is passed, by reference, to other
objects created during the duration of the program.
I think I've finally isolated why my program is "bombing out" when I
execute the multi-threaded version. In the destructor for this Log
class, I close the log file object. Well, multiple threads are
writing to this object and the first thread that exits will, because
in that thread other objects are created that take a reference to this
log object, close the log file. Thus the program exits with with
complaints from the Runtime and a prompt to debug in VS.
I'm hoping for guidance in evaluation of the solutions I've determined
thus far. From what I can see, I have two main solutions, the second
of which has some further code implementation issues.
|