|
-
January 29th, 2010, 12:49 AM
#1
Object in its own thread?
Hi,
I'm new to this forum and to thread programming.
Been wondering if it's possible for an object to exist in its own thread, so that different instances can run their various methods in their own thread space.
The root of my problem is this:
I've got a few pieces of the same hardware, and I created a class to represent it. Because of how the hardware works, I've got to poll after sending a command to it (by calling an API function) and wait for completion. Now, the different pieces can work simultaneously, but I can't send two commands to the same piece at once.
By running everything in one (main) thread, different pieces of hardware hold each other up.
Code:
int main()
{
myObj obj1, obj2;
// need the 2 objects to execute almost simultaneously
// at the moment, obj2 will only execute after obj1 is done with its job
obj1.doSomething();
obj2.doSomething();
// again, 2 objects to execute simultaneously, upon completion of the previous commands
obj1.doSomethingElse();
obj2.doSomethingElse();
return 0;
}
I've been reading up about the thread object wrapper, but it seems like I need to re-wrap every single method within my custom object.
There's also the singleton pattern, but I'm still reading up on that.
Can anyone point me in the correct direction?
Last edited by radioactive28; January 31st, 2010 at 11:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|