Hi everybody
We are creating an application using the INONGUITHREAD class of Visual Age C++.
The problem we have is that we created a class called iThread to encapsulate this class
and our application calls threads in a recursive way in 2 levels, it means, we have a thread
used to generate other threads (We don´t know if recursive threads may affect) and if we run only
one thread our application works successfully, the problem is with multithread ( when we use the thread
to generate other threads) because the paging space grows up continuously until the application
dumps.
Here is the code we are using:
iThread.h
// ***************************************************************************************
// Class iThread
//
// Definition of the class iThread
//
// ***************************************************************************************
#ifndef _IPROCESS_HEADER_FILE_CLASS_ITHREAD_
#define _IPROCESS_HEADER_FILE_CLASS_ITHREAD_
#include "ithread.hpp"
#include "ingthrd.hpp"
#define ITHREAD_WAITING_FINISHED 50
class iThread
{
public:
static const INonGUIThread::EThreadPriority PriorityPanic;
static const INonGUIThread::EThreadPriority PriorityHigh;
static const INonGUIThread::EThreadPriority PriorityMedium;
static const INonGUIThread::EThreadPriority PriorityLow;
public:
iThread(void);
inline virtual ~iThread(void) { }
void run(INonGUIThread::EThreadPriority priority = iThread:riorityMedium);
virtual void finish(void);
private:
void thread(void);
protected:
virtual void process(void) = 0;
protected:
bool Running;
private:
bool FinishRequested;
bool Finished;
INonGUIThread::EThreadPriority Priority;
};
#endif //_IPROCESS_HEADER_FILE_CLASS_ITHREAD_
ithread.cpp
// ***************************************************************************************
// Class iThread
//
// Implementation of the class iThread
//
// ***************************************************************************************
#include "iThread.h"
const INonGUIThread::EThreadPriority iThread:riorityPanic = INonGUIThread::timeCritical;
const INonGUIThread::EThreadPriority iThread:riorityHigh = INonGUIThread::aboveNormal;
const INonGUIThread::EThreadPriority iThread:riorityMedium = INonGUIThread::normal;
const INonGUIThread::EThreadPriority iThread:riorityLow = INonGUIThread::belowNormal;
// ***************************************************************************************
// Constructor :: iThread
// ***************************************************************************************
iThread::iThread(void)
{
Running = TRUE;
FinishRequested = FALSE;
Finished = FALSE;
}
// ***************************************************************************************
// run :: iThread
// ***************************************************************************************
void iThread::run(INonGUIThread::EThreadPriority priority)
{
Priority = priority;
INonGUIThread processThread(new IThreadMemberFn<iThread>((*this),&iThread::thread));
}
// ***************************************************************************************
// finish :: iThread
// ***************************************************************************************
void iThread::finish(void)
{
FinishRequested = TRUE;
Running = FALSE; // Suggest thread to stop
// Waits until the process finishes and delete the object
while( !Finished )
ICurrentNonGUIThread::current().sleep(ITHREAD_WAITING_FINISHED);
delete this;
}
// ***************************************************************************************
// thread :: iThread
// ***************************************************************************************
void iThread::thread(void)
{
// Change the priority of the thread to the specify
ICurrentNonGUIThread::current().setThreadPriority( Priority );
// Execute the custom process
this->process();
if( FinishRequested )
{
Finished = TRUE;
}
else
{
delete this;
}
}
Is this the correct way to use the INonGUIThread?
INonGUIThread processThread(new IThreadMemberFn<iThread>((*this),&iThread::thread));
Thanks in advance...
We are creating an application using the INONGUITHREAD class of Visual Age C++.
The problem we have is that we created a class called iThread to encapsulate this class
and our application calls threads in a recursive way in 2 levels, it means, we have a thread
used to generate other threads (We don´t know if recursive threads may affect) and if we run only
one thread our application works successfully, the problem is with multithread ( when we use the thread
to generate other threads) because the paging space grows up continuously until the application
dumps.
Here is the code we are using:
iThread.h
// ***************************************************************************************
// Class iThread
//
// Definition of the class iThread
//
// ***************************************************************************************
#ifndef _IPROCESS_HEADER_FILE_CLASS_ITHREAD_
#define _IPROCESS_HEADER_FILE_CLASS_ITHREAD_
#include "ithread.hpp"
#include "ingthrd.hpp"
#define ITHREAD_WAITING_FINISHED 50
class iThread
{
public:
static const INonGUIThread::EThreadPriority PriorityPanic;
static const INonGUIThread::EThreadPriority PriorityHigh;
static const INonGUIThread::EThreadPriority PriorityMedium;
static const INonGUIThread::EThreadPriority PriorityLow;
public:
iThread(void);
inline virtual ~iThread(void) { }
void run(INonGUIThread::EThreadPriority priority = iThread:riorityMedium);
virtual void finish(void);
private:
void thread(void);
protected:
virtual void process(void) = 0;
protected:
bool Running;
private:
bool FinishRequested;
bool Finished;
INonGUIThread::EThreadPriority Priority;
};
#endif //_IPROCESS_HEADER_FILE_CLASS_ITHREAD_
ithread.cpp
// ***************************************************************************************
// Class iThread
//
// Implementation of the class iThread
//
// ***************************************************************************************
#include "iThread.h"
const INonGUIThread::EThreadPriority iThread:riorityPanic = INonGUIThread::timeCritical;
const INonGUIThread::EThreadPriority iThread:riorityHigh = INonGUIThread::aboveNormal;
const INonGUIThread::EThreadPriority iThread:riorityMedium = INonGUIThread::normal;
const INonGUIThread::EThreadPriority iThread:riorityLow = INonGUIThread::belowNormal;
// ***************************************************************************************
// Constructor :: iThread
// ***************************************************************************************
iThread::iThread(void)
{
Running = TRUE;
FinishRequested = FALSE;
Finished = FALSE;
}
// ***************************************************************************************
// run :: iThread
// ***************************************************************************************
void iThread::run(INonGUIThread::EThreadPriority priority)
{
Priority = priority;
INonGUIThread processThread(new IThreadMemberFn<iThread>((*this),&iThread::thread));
}
// ***************************************************************************************
// finish :: iThread
// ***************************************************************************************
void iThread::finish(void)
{
FinishRequested = TRUE;
Running = FALSE; // Suggest thread to stop
// Waits until the process finishes and delete the object
while( !Finished )
ICurrentNonGUIThread::current().sleep(ITHREAD_WAITING_FINISHED);
delete this;
}
// ***************************************************************************************
// thread :: iThread
// ***************************************************************************************
void iThread::thread(void)
{
// Change the priority of the thread to the specify
ICurrentNonGUIThread::current().setThreadPriority( Priority );
// Execute the custom process
this->process();
if( FinishRequested )
{
Finished = TRUE;
}
else
{
delete this;
}
}
Is this the correct way to use the INonGUIThread?
INonGUIThread processThread(new IThreadMemberFn<iThread>((*this),&iThread::thread));
Thanks in advance...