Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<thread>
  5. using namespace std;
  6. bool s1, s2;
  7. int turno, c;          //contador
  8. float kw;   //numero de kw
  9. void Process1(){
  10.     while(turno==1 && c<60){
  11.         s1=true;
  12.         turno=2;
  13.         while(s2==true && turno==2){}
  14.         c=c+1;
  15.         s1=false;
  16.     }
  17. }
  18. void Process2(){
  19.     while(turno==2 && c<60){
  20.         s2=true;
  21.         turno=1;
  22.         while(s1==true && turno==1){}
  23.         kw=(26*c);
  24.         cout<<"\nEn "<<c<<" min se consumieron: "<<kw<<"Kw";
  25.         s2=false;
  26.     }
  27. }
  28. int main(){
  29.     s1=false;
  30.     s2=false;
  31.     turno=2;
  32.     c=0;
  33.     thread th1(Process1);
  34.     thread th2(Process2);
  35.     if(th1.joinable() && th2.joinable()){
  36.         th2.join();
  37.         th1.join();
  38.     }
  39.     getch();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement