Boost logo

Boost :

From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-08-05 14:17:06


PlatformSpecificThread is a concrete class--not a template. There is no
"selection", it is only defined in the localized thread implementation. The
key is the pre-declaration. I can see how it might be considered the PIMPL
idiom, however, doesn't that idiom require a base class and polymorphism
(virtual methods)? This has none of those.

Isn't the problem with mutexs only to be blamed on the allocator used?
Otherwise the entire object-oriented paradigm is meaningless.

----- Original Message -----
From: Moore, Dave
Newsgroups: gmane.comp.lib.boost.devel
Sent: Monday, 2002:August:05 2:44 PM
Subject: RE: Platform Neutrality - without reinterpret_cast<> andifdef

Eric,

What would "client" code look like for this method? In other words, for
portable client code, how is the template class PlatformSpecificThread
selected?

In general, this is a realization of the pointer-to-implementation (Pimpl)
idiom. For thread objects, the cost of the "new PlatformSpecificThread" is
of course trivial comparied to the overhead of creating a thread.

However, if you extend this approach to boost::mutex, the cost of dynamic
allocation and indirection may be large on platforms where mutexes are
inexpensive to create and destroy. (IIRC, this concern was raised during
the formal review of Boost.Threads).

Regards,
Dave

p.s. I hope you don't think I'm badgering you - my interest in techniques
for "clean" cross-platform code goes beyond this topic, and I'm always up
for seeing a new method.

-----Original Message-----
From: Eric Woodruff [mailto:Eric.Woodruff_at_[hidden]]
Sent: Monday, August 05, 2002 2:15 PM
To: boost_at_[hidden]
Subject: [boost] Platform Neutrality - without reinterpret_cast<> and ifdef

Here's how to provide platform neutrality while keeping typesafety and
avoiding #ifdef:

I will fabricate an example loosely based on boost::thread.

// thread.hpp

namespace boost {

    class thread {
        public:
            //...
        private:
            void runAsynchronousMethod () {
                // run our happy boost::function
                // deal with exceptions
            }

            boost::shared_ptr<class PlatformSpecificThread> psThread; //
must be last attribute to make sure "this" is fully constructed before
thread starts.
            friend class PlatformSpecificThread;
    };
}
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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