Boost logo

Boost :

From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-08-06 12:10:56

Here's another option:

As I suggest before, to use a secondary class with the specific
implementation in it, why not make it a flag that the user can set whether
to use a "PIMPL" or just a normal instance of it. Some people might rather
not have <windows.h> or <pthread.h> include in their dependency hierarchy --
this is after all, one of the key points of the abstraction.


// thread.hpp


#include <boost/thread/platform_implementations.hpp>

namespace boost {
    class thread {
            // ...

            threads::PlatformSpecificThread platformThread; // i'll address
the pointer vs non-pointer
            threads::PlatformSpecificThread* platformThread;


// platform impelmentations.hpp

#include <boost/thread/win32_thread_implementation.hpp>
#include <boost/thread/posix_thread_implementation.hpp>

// win32_thread_implementation

#ifdef WIN32

#include <Windows.h>

namespace boost {
    namespace threads {
        class PlatformSpecificThread {

            HANDLE threadHandle;

            PlatformSpecificThread* operator-> () { return this; }
            // this will keep the code generic between PIMPL and PIMPL-free


// thread.cpp - win32 version

using boost::thread;

// only the constructor is sentient of the difference.

#include <boost/thread/win32_thread_implementation.hpp>

thread::thread (...) {

thread::thread (...)
    : platformThread (new threads::PlatformSpecificThead (this)) {


// a very trivialized but clean version of join (example only)
thread::join () {
    WaitForMultipleObjectsEx (platformThread->Handle,...);

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