Overview
Features
Download
Documentation
Community
Add-Ons & Services

Active Method Question

Please post support and help requests here.

Active Method Question

Postby eswanson » 29 Jan 2009, 21:13

I am attempting to use the active method in a class. Basically here is the class:

class CTmp:
testVoidInOut(this,&CTmp::ThreadFunc)
{
public:
typedef ActiveMethod<void, void, CTmp> VoidVoidType;

bool IsThreadFinished();

void StartThread() {testVoidInOut;}

VoidVoidType testVoidInOut;

void ThreadFunc();
};

main
{
CTmp objTmp;
objTmp.StartThread();
// do some other processing that is not thread related
objTmp.IsThreadFinished();
}

What code can I put in the IsThreadFinished method to tell if the thread has finished? Is there sometype of notification(s) that will allow me to be notified when the thread is finished?

Thanks

Eric

}
eswanson
 
Posts: 13
Joined: 29 Jan 2009, 16:01

Re: Active Method Question

Postby Javaddiction » 01 Feb 2009, 16:49

You could either check a boolean (ideally protected by a mutex) or use a Poco::Event where the active method thread calls "set()" on the event and the main thread blocks appropriately on the event's "wait()" or "tryWait()" methods.

Given your description, it seems more appropriate to just use a Poco::Thread. You can either make CTmp subclass Poco::Runnable or, better yet, utilize the Poco::RunnableAdapter which allows just about any method to run in a thread without any other special interface requirements. Then whenever you want to check if the thread is running, just call isRunning() on the instance of the thread class :)
Javaddiction
 
Posts: 2
Joined: 19 Jan 2009, 14:56

Re: Active Method Question

Postby eswanson » 02 Feb 2009, 14:55

thanks for the information. I will give the Poco::Runnable a try.

Eric
eswanson
 
Posts: 13
Joined: 29 Jan 2009, 16:01


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron