Boost logo

Boost :

From: Dave Abrahams (dave_at_[hidden])
Date: 2003-02-06 10:28:16


On Wednesday, February 05, 2003 4:05 PM [GMT+1=CET],
William E. Kempf <wekempf_at_[hidden]> wrote:

> > On Wednesday, February 05, 2003 3:04 PM [GMT+1=CET],
> > William E. Kempf <wekempf_at_[hidden]> wrote:
> >
> > > > What I would like to see is a new boost::thread implementation
> > > which meets the following requirements.
> > > >
> > > > a. There shall be two interfaces to a thread. One for creation of a
> > > > thread, from here on called boost::thread. And, one for the
> > > > created thread, from here on called boost::thread::self.
> > >
> > > Self? Why? If it's on operation that can *only* be made on the
> > > current thread, then a static method is a better approach. Otherwise,
> > > I could make a "self" instance and pass it to another thread, which
> > > could then attempt an operation that's not valid for calling on
> > > another thread.
> >
> > It would seem to me that, given the availability of p->yield() as a
> > syntax for invoking a static function, it'd be better to use a
> > namespace-scope function to avoid errors and for clarity.
>
> OK, I can buy that over a seperate self class. This was discussed at one
> point, but the particular issue with p->yield() was never brought up. I'm
> not sure I find it compelling, because which thread yields should be
> evident from the documentation, and I don't see anyone ever using this
> syntax. But compelling or not, I'm not opposed to making this a free
> function if others think it's clearer in this regard.

Here's the extent of my argument:

1. It's easy to miss "static" in a member function declaration
2. Various things lead people to write this->foo() even for static functions
3. Other people reading that code may tend to write that->foo()

Anyway, I'm not heavily committed to this argument, but I've grown away from
using static member functions in this way, and tend toward free functions
for clarity. Now I tend to just use static members as a way of carrying a
function along with a type in a metaprogramming context -- the type gets
passed to a template and the function can then be used -- much like using
function pointers as template parameters.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk