Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iomanip>
- #include <iostream>
- #include <pthread.h>
- #include <unistd.h>
- using namespace std;
- void* func1(void* a){
- bool*flag1=(bool*)a;
- while(*flag1 ){
- cout<< "1"<< flush;
- sleep(1);
- }
- pthread_exit((void*)3);
- }
- void* func2(void* a){
- bool*flag2=(bool*)a;
- while(*flag2){
- cout<< "2"<< flush;
- sleep(1);
- }
- pthread_exit((void*)4);
- }
- int main(){
- bool flag1=true;
- bool flag2=true;
- pthread_t thread1,thread2;
- pthread_create(&thread1, NULL, func1, &flag1);
- pthread_create(&thread2, NULL, func2, &flag2);
- getchar();
- flag1=false;
- flag2=false;
- void* st1;
- void* st2;
- pthread_join(thread1, &st1);
- pthread_join(thread2, &st2);
- cout<<"status 1,2:"<<((int*)st1)<<" "<<((int*)st2);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement