Boost logo

Boost :

From: Moore, Dave (dmoore_at_[hidden])
Date: 2002-08-05 13:44:14


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

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).


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 {
            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;

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