From: Johan Nilsson (johan.nilsson_at_[hidden])
Date: 2004-06-09 02:12:34
"Rob Stewart" <stewart_at_[hidden]> wrote in message
> From: Michael Glassford <glassfordm_at_[hidden]>
> > Rob Stewart wrote:
> > > Do you really want to account for the creation and joining of
> > > threads outside of main()? I'm no MT expert, but I recall
> > > learning that one should avoid creating threads prior to main.
> > > It makes statics and even main() difficult to write. Isn't
> > > that correct? If so, should Boost.Thread really account
> > > for bad designs?
> > The biggest problem with this is that global static objects are
> > initialized before main(). Is it necessarily a bad thing for the
> > constructor of such an object to create a thread?
> My understanding is that it is a problem, but I may be wrong.
> The problems you run into with permitting threads before main()
> is that you have to make access to shared resources thread safe
> when accessed by static objects that can be created in any order
> and main() can't do any required initialization without worrying
> about thread safety. The better approach is for statics to be
> initialized in a single thread and for main() to do its
> initialization and, only then, does main() cause the various
> threads to come into existence.
You are assuming that the author of main() knows all about the inner works
of all objects it makes use of (directly as well as indirectly). I believe
that he/she should not necessarily have to.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk