Link to home
Start Free TrialLog in
Avatar of cw1592
cw1592

asked on

same function name form different classes used in pthread

I try to implement multi-threading on Linux using C/C++ using pthread, but got a question:
how can I use the same function name from two different classes in the pthread's pthread_create?

more precisely:
I have two classes by using a template, so they are:
==============================================================
class buyerA {
order(item);
pay(total);
}

class buyerB {
order(item);
pay(total);
}
==============================================================
now I like use the pthread library, how can I create threads for these two buyers?
can I do (assume A is one instance of Class A, and B is another instance of ClassB):
==============================================================
pthread_create(pt1, NULL, A.order(), NULL, item1);
pthread_create(pt2, NULL, B.order(), NULL, item2);

....

pthread_create(pt1, NULL, A.pay(), NULL, total1);
pthread_create(pt2, NULL, B.pay(), NULL, total2);

.....
=================================================

Thanks for the help.
SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cw1592
cw1592

ASKER

thanks for the comments; maybe I should use the Boost libray?can I do something like:

boost::thread* pThread = new boost::thread(
    boost::bind(
    &ClassA::ret_val,             // member function
    &theClassA) );              // instance of class

could you advice on which approach will be better (pthres or boost) in this situtaiton where a tmeplate is used to get more than one class, and threas are generated based on the member funcitons in classes (from the virtual funcitons from the tamplate)?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cw1592

ASKER

thanks to all, these comments help.