Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by std ( 14 years ago )
int pipes[TREADS][2];
 float avg;

 for(int id_proc = 0; id_proc < TREADS; id_proc++) {
  pid_t p;
  float sraf = 0;
  p = fork();
  if(p == 0) {
   for (int i = id_proc; i < mas.size(); i+=TREADS)
    sraf += mas[i];
   sraf /= mas.size();
   cout << "Среднее арифметическое: " << sraf << endl;
   avg = sraf;
   write(pipes[id_proc][1],&avg;,sizeof(avg));
   return 1;
  }
  else 
   waitpid(p,0,0);
 }

 for(int id_proc = 0; id_proc < TREADS; id_proc++) {
  read(pipes[id_proc][0],&avg;,sizeof(avg));
  cout << avg << endl;
 }

 

Revise this Paste

Your Name: Code Language: