Boost logo

Boost Users :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-09-03 10:32:02


--- In Boost-Users_at_y..., "Ani Taggu" <yg-boost-users_at_m...> wrote:
> Hello:
>
> I have a simple class to do simple thread-safe logging using
recursive_mutex
> as shown below. The problem is, once in a while, it causes any
thread to die
> while it tries to log. I haven't been able to isolate why this
happens. Is
> recursive_mutex being used correctly?

I'm not sure I can answer why threads would "die". I'm going to
assume there's an exception being thrown in the thread, but that's
just a guess.

I will comment on your logger, though. It's flawed. The stream
library provided on your platform/compiler already provide the level
of thread synchronization that your logger does. The problem is
that this level of thread synchronization granularity is not
enough. Consider your use case:

TheLog() << "Hello World" << endl;

The stream is synchronized when outputting "Hello World" and when
outputting the "endl" manipulator, but not between these two
seperate calls. This means your output can be interleaved, and
basically be unreadable because of this. You really want to make
the entire output sequence syncrhonized.

I'm also uncertain why you'd use a recursive_mutex in this case?

Bill Kempf


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net