EXT Win Library - threadc

The win::threadc template encapsulates a thread as an object created over specified class/object member function.


Interface:

template <typename C, int (C::*P) (void *), unsigned int stack = 0>
class win::threadc {
    public:
        explicit threadc (void * = 0);
        explicit threadc (C & c, void * = 0);
        ~threadc () throw ();

    private:
        threadc (const threadc &);
        threadc & operator = (const threadc &);

    public:
        bool running () const throw ();
        bool failed () const throw ();

        int  result () const throw ();
        void wait () const throw ();
};

Details:

The thread is considered an object. It is created when the object is constructed and finishes along with destruction of the object or sooner. The destructor waits until the thread procedure ends. The thread object cannot be copied.

To define the thread class provide a class name, pointer to a member function and optionaly initial stack size for the thread to the win::threadc template. When creating the object you may pass a reference to an object in whose context the member function is executed. If no reference is provided a temporary object of the class C is created. You may also pass a optional parameter of void * type (defaults to NULL) that is provided to the member function executed in the thread.

You will need to include "ext/win_bits/thread.cpp" into your project in order to use win::threadc.

Examples:

#include <ext/win>

class Class {
    int Procedure (void *) {
        // ...
        return 0;
    };
};

int main () {
    win::thread <Class, &Class::Procedure> thread;
    win::thread <Class, &Class::Procedure> thread (ptr);

    Class c;
    win::thread <Class, &Class::Procedure> thread (c);
    win::thread <Class, &Class::Procedure> thread (c, ptr);
    // ...
    return 0;
};

Remarks

Use win::thread template to create threads on first-class functions.


[index]