Example : Sync.C

Classes/Techniques Demonstrated :

Sync.C demonstrates the basics of the HPCxx_Sync class. It creates several threads, all of which block on a Sync variable, waiting to be released. The user inputs a number indicating which thread to release, which causes the program to write to that thread's Sync variable, releasing it.
class Worker: public HPCxx_Thread {
  HPCxx_Sync<int> &s;
  int myID;
  public:
     Worker(HPCxx_Sync &s_, int i): s(s_), myID(i), HPCxx_Thread()
     {
        cout << "Thread " << myID << " init complete" << endl;
     }
     void run() 
     {
       int x;
       x=s;
       cout << "Thread " << myID << " thanks you for your support " << endl;
     }
};

int main(int argc, char **argv)
{
  int tr=-1, nw=NUMWORKERS, far[NUMWORKERS];
  HPCxx_Group *g;
  HPCxx_Sync<int> sar[NUMWORKERS];

  hpcxx_init(argc, argv, g);
  for(int i=0; istart();
    far[i]=0;
  }
  while(nw) {
    while(tr==-1 || far[tr]) {
      cout << endl << endl << endl << "Thread to release ->";
      cin >> tr;
    }
    sar[tr]=tr;
    far[tr]=1;
    tr=-1;
    nw--;
  }
  hpcxx_exit(g);
  return 0;
}
    

hpc++@extreme.indiana.edu

Last modified: Thu Apr 22 02:12:11 EST 1999