#include #include #include #include int count = 0; void *threadfunc(void *arg){ cout<<"Thread Complete\n"; count++; return NULL; } int main(){ count = 0; pthread_t A,B,C; pthread_create(&A, NULL, threadfunc, NULL); pthread_create(&B, NULL, threadfunc, NULL); pthread_create(&C, NULL, threadfunc, NULL); while(count<50) { pthread_join(A, NULL); if(count<50) pthread_join(B, NULL); if(count<50) pthread_join(C, NULL); } return 0; }     What is wrong?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int count = 0;

void *threadfunc(void *arg){

cout<<"Thread Complete\n";

count++;

return NULL;

}

int main(){

count = 0;

pthread_t A,B,C;
pthread_create(&A, NULL, threadfunc, NULL);

pthread_create(&B, NULL, threadfunc, NULL);

pthread_create(&C, NULL, threadfunc, NULL);

while(count<50)

{
pthread_join(A, NULL);

if(count<50)

pthread_join(B, NULL);

if(count<50)

pthread_join(C, NULL);

}

return 0;

}

 

 

What is wrong? 

main.c
Run
Output
1 #include spthread.h>
gcc /tmp/YnbMRODlqg.c -lm
/tmp/YnbMRODlqg.c: In function 'threadfunc':
/tmp/YnbMRODlqg.c:10:1: error: 'cout' undeclared (first use in this function); did you mean "count'?
10 | couts<"Thread Complete\n";
1
#include <stdio.h>
3 #include <unistd.h>
4 #include <stdlib.h>
6 int count = 0;
| count
7
/ tmp/YnbMRODlqg.c:10:1: note: each undeclared identifier is reported only once for each function it appears in
8- void *threadfunc(void *arg){
9
10 cout<<"Thread Complete\n";
11
12 count-+:
JS
13
14 return NULL;
15
16 }
17
18 - int main()
19
20 count = 0;
21
22 pthread_t A,B.C:
23 pthread_create(&A, NULL, threadfunc, NULL);
24
25 pthread_create(&B, NULL, threadfunc, NULL);
26
27 pthread_create(&C, NULL, threadfunc, NULL);
28
29 while(count<50)
30
31- {
32 pthread_join(A, NULL);
33
34 if(count<50)
35
36 pthread_join(B. NULL);
37
38 if(count<50)
39
40 pthread_join(C, NULL):
41
42 }
43
44 return 0;
45
46
Transcribed Image Text:main.c Run Output 1 #include spthread.h> gcc /tmp/YnbMRODlqg.c -lm /tmp/YnbMRODlqg.c: In function 'threadfunc': /tmp/YnbMRODlqg.c:10:1: error: 'cout' undeclared (first use in this function); did you mean "count'? 10 | couts<"Thread Complete\n"; 1 #include <stdio.h> 3 #include <unistd.h> 4 #include <stdlib.h> 6 int count = 0; | count 7 / tmp/YnbMRODlqg.c:10:1: note: each undeclared identifier is reported only once for each function it appears in 8- void *threadfunc(void *arg){ 9 10 cout<<"Thread Complete\n"; 11 12 count-+: JS 13 14 return NULL; 15 16 } 17 18 - int main() 19 20 count = 0; 21 22 pthread_t A,B.C: 23 pthread_create(&A, NULL, threadfunc, NULL); 24 25 pthread_create(&B, NULL, threadfunc, NULL); 26 27 pthread_create(&C, NULL, threadfunc, NULL); 28 29 while(count<50) 30 31- { 32 pthread_join(A, NULL); 33 34 if(count<50) 35 36 pthread_join(B. NULL); 37 38 if(count<50) 39 40 pthread_join(C, NULL): 41 42 } 43 44 return 0; 45 46
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Random access
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education