Boost logo

Boost :

From: Mattias Flodin (flodin_at_[hidden])
Date: 2002-04-09 13:19:18

On Mon, Apr 08, 2002 at 09:47:35PM -0400, Ernie Makris wrote:
> - Parameterizeable thread safety. Don't penalize programs that do not need
> thread
> safe logs.

A feature I'd like here is that the log library allows for easily (and
seamlessly, if possible) setting up thread-local logs with some kind of
optional merging functionality. An elaboration follows.

One of the most common occasions when I find the need for a debug log is in
dealing with parallel algorithms. Why? Because in plain and simple
single-threaded apps using the interactive debugger works great most of the
time. With a parallel algorithm the debugger isn't so great anymore. If it
works at all, race conditions etc are very hard to spot with a conventional
debugger. Furthermore, most heavyweight parallel computers are batch systems,
which leaves interactive debuggers out of the question.

However, with logging comes a rather interesting problem. Because a file is a
shared object, writing to a file is a kind of synchronization operation in
its own right. Meaning that if you have many threads writing log messages to
the file, their originally parallel operation is serialized by the logging
operation. Your trace outputs causes the malfunctioning program to start
working again! Trying to solve it by using a memory area instead of a file
won't lead anywhere since you still have to synchronize access to end-of-log

This has lead me to write my log routines (yes, I have many wheel designs
too :) so that each thread has its own memory area or file in which log lines
are stored. The lines are timestamped, so that after a parallel section has
been run, the log can be "flushed" in such a way that the lines are merged in
chronological order. In other situations the merging is unwanted; looking at
a few different files from different threads is more enlightening (gives you
a better view on communication patterns as opposed to order of events).


Mattias Flodin <flodin_at_[hidden]>  -
Room NADV 102
Department of Computing Science
Umeå University
S-901 87 Umeå, Sweden
Unlike more superficial forms of expertise, mathematics is a way of saying
less and less about more and more.
  -- G. Spencer Brown (Laws of Form, page V)

Boost list run by bdawes at, gregod at, cpdaniel at, john at