B
Bryan
Im new to threading and am experiencing some confusion as to how to
correctly use AfxBeginThread in my singleton class. The code that I
want to thread out is in a single function, Init(). Is AfxBeginThread
the right way to thread off a single worker thread? It seems like it.
But what are the correct args for it, my code wont compile. And does my
class need to be restructured? How?
Thanks,
Bryan
I have this:
class CHandler
{
public:
~CHandler(void);
static CHandler& Instance();
bool GetInitialized() { return m_initialized; }
private:
CHandler(void);
CHandler(const CHandler&);
CHandler& operator=(const CHandler&);
void Init(LPVOID pParam);
bool m_initialized;
};
CHandler::CHandler(void)
{
Init();
}
CHandler::~CHandler(void)
{
// clean up code
}
CHandler& CHandler::Instance()
{
static CHandler instance;
// This is something like what I want to add to thread Init()
//if (!instance.GetInitialized()) {
// AfxBeginThread(Init, &instance);
//}
return instance;
}
void CHandler::Init(LPVOID pParam)
{
// I dont need pParam here (I think) do I have to have it?
try {
// Specific call to other code that I want to thread!
// This stuff takes forever and only can happen 1x!
if (!mclInitializeApplication(NULL,0))
{
throw std::exception("");
}
if (!clusterlibInitialize())
{
throw std::exception("");
}
m_initialized = true;
}
catch(...) {
m_initialized = false;
}
}
correctly use AfxBeginThread in my singleton class. The code that I
want to thread out is in a single function, Init(). Is AfxBeginThread
the right way to thread off a single worker thread? It seems like it.
But what are the correct args for it, my code wont compile. And does my
class need to be restructured? How?
Thanks,
Bryan
I have this:
class CHandler
{
public:
~CHandler(void);
static CHandler& Instance();
bool GetInitialized() { return m_initialized; }
private:
CHandler(void);
CHandler(const CHandler&);
CHandler& operator=(const CHandler&);
void Init(LPVOID pParam);
bool m_initialized;
};
CHandler::CHandler(void)
{
Init();
}
CHandler::~CHandler(void)
{
// clean up code
}
CHandler& CHandler::Instance()
{
static CHandler instance;
// This is something like what I want to add to thread Init()
//if (!instance.GetInitialized()) {
// AfxBeginThread(Init, &instance);
//}
return instance;
}
void CHandler::Init(LPVOID pParam)
{
// I dont need pParam here (I think) do I have to have it?
try {
// Specific call to other code that I want to thread!
// This stuff takes forever and only can happen 1x!
if (!mclInitializeApplication(NULL,0))
{
throw std::exception("");
}
if (!clusterlibInitialize())
{
throw std::exception("");
}
m_initialized = true;
}
catch(...) {
m_initialized = false;
}
}