Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<stdlib.h>
- #include<thread>
- using namespace std;
- bool s1, s2;
- int turno, c; //contador
- float kw; //numero de kw
- void Process1(){
- while(turno==1 && c<60){
- s1=true;
- turno=2;
- while(s2==true && turno==2){}
- c=c+1;
- s1=false;
- }
- }
- void Process2(){
- while(turno==2 && c<60){
- s2=true;
- turno=1;
- while(s1==true && turno==1){}
- kw=(26*c);
- cout<<"\nEn "<<c<<" min se consumieron: "<<kw<<"Kw";
- s2=false;
- }
- }
- int main(){
- s1=false;
- s2=false;
- turno=2;
- c=0;
- thread th1(Process1);
- thread th2(Process2);
- if(th1.joinable() && th2.joinable()){
- th2.join();
- th1.join();
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement