Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use the INONGUITHREAD class implemented in Visual Age C++?

Status
Not open for further replies.

chavax

Programmer
Jan 17, 2002
9
US
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::priorityMedium);
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::priorityPanic = INonGUIThread::timeCritical;
const INonGUIThread::EThreadPriority iThread::priorityHigh = INonGUIThread::aboveNormal;
const INonGUIThread::EThreadPriority iThread::priorityMedium = INonGUIThread::normal;
const INonGUIThread::EThreadPriority iThread::priorityLow = 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...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top