class MyThread: public HPCxx_Thread{
HPCxx_SyncQ<int> *sync;
int my_num;
public:
MyThread( HPCxx_SyncQ *s , int m ): HPCxx_Thread(){
my_num = m;
sync = s;
cout << "constructor complete" << endl;
}
void run(){
cout << "thread " << my_num << " sleeping..." << endl;
sleep((10-my_num));
*sync=my_num;
cout << "thread " << my_num << " inserted value : " << my_num << endl;
}
};
int foo(int n) {
HPCxx_SyncQ<int> s;
MyThread *t[100];
int temp;
for(int i = 0; i < n; i++){
t[i] = new MyThread(&s, i);
t[i]->start();
}
for(i=0; i<n; i++) {
temp=s;
cout << "foo() recevied value " << temp << endl;
}
return 0;
}
int main(int argc, char *argv[]){
HPCxx_Group *g;
hpcxx_init(argc, argv, g);
int x;
cout << "num threads:" ;
cin >> x;
cout << "doing " << x << "threads.";
foo(x);
printf("done with read\n");
printf("DONE\n");
hpcxx_exit(g);
return(0);
} /* main() */
Last modified: Thu Apr 22 02:12:19 EST 1999