Discuss in your own word the function and output of the two programs.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Discuss in your own word the function and output of the two programs.

thread01.c
A Get Started
C thread0.c
C thread01.c X
D I ...
Volumes > RVPELLEGRINO > MAPUA > CPE105 > WEEK2 > C thread01.c > O main()
// thread01.c
2 v #include <pthread.h>
3
#include <stdio.h>
4.
#include <stdlib. h>
#define N 5
7
8 v void *worker_thread (void *arg)
9
{
10
printf("This is worker_thread #%ld\n", (long)arg);
11
pthread_exit(NULL);
12
}
13
14 v int main()
15
16
pthread_t my_thread [N];
17
long id;
for(id = 1; id <= N; id++) {
18
19 v
int ret = pthread_create(&my_thread [id], NULL, &
worker_thread, (void*)id);
20
21 v
if(ret != 0) {
printf("Error: pthread_create() failed\n");
exit (EXIT_FAILURE);
22
23
24
}
25
}
26
27
pthread_exit(NULL);
28
PROBLEMS
OUTPUT
TERMINAL
DEBUG CONSOLE
Code
[Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread0.c -o threado && "/v
In main: creating thread
This is worker_thread ()
[Done] exited with code=0 in 0.298 seconds
[Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread01.c -o thread@1 &&
This is worker_thread #3
This is worker_thread #1
This is worker_thread #2
This is worker_thread #4
This is worker_thread #5
[Done] exited with code=0 in 0.16 seconds
Transcribed Image Text:thread01.c A Get Started C thread0.c C thread01.c X D I ... Volumes > RVPELLEGRINO > MAPUA > CPE105 > WEEK2 > C thread01.c > O main() // thread01.c 2 v #include <pthread.h> 3 #include <stdio.h> 4. #include <stdlib. h> #define N 5 7 8 v void *worker_thread (void *arg) 9 { 10 printf("This is worker_thread #%ld\n", (long)arg); 11 pthread_exit(NULL); 12 } 13 14 v int main() 15 16 pthread_t my_thread [N]; 17 long id; for(id = 1; id <= N; id++) { 18 19 v int ret = pthread_create(&my_thread [id], NULL, & worker_thread, (void*)id); 20 21 v if(ret != 0) { printf("Error: pthread_create() failed\n"); exit (EXIT_FAILURE); 22 23 24 } 25 } 26 27 pthread_exit(NULL); 28 PROBLEMS OUTPUT TERMINAL DEBUG CONSOLE Code [Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread0.c -o threado && "/v In main: creating thread This is worker_thread () [Done] exited with code=0 in 0.298 seconds [Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread01.c -o thread@1 && This is worker_thread #3 This is worker_thread #1 This is worker_thread #2 This is worker_thread #4 This is worker_thread #5 [Done] exited with code=0 in 0.16 seconds
A Get Started
D O ...
C thread0.c x
Volumes > RVPELLEGRINO > MAPUA > CPE105 > WEEK2 > C thread0.c > O main()
// thread0.c
ww.A -
#include <pthread.h>
G...
3
#include <stdio.h>
4.
#include <stdlib.h>
void *worker_thread (void *arg)
7
{
printf("This is worker_thread ()\n");
pthread_exit(NULL);
8
9.
10
}
11
12
int main()
13
14
pthread_t my_thread;
15
int ret;
16
printf("In main: creating thread\n");
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
if(ret != 0) {
17
18
19
printf("Error: pthread_create() failed\n");
exit(EXIT_FAILURE);
20
21
22
}
23
24
pthread_exit(NULL);
25
v E 6 O ^ x
PROBLEMS
OUTPUT
TERMINAL
DEBUG CONSOLE
Code
/Library/Developer/CommandLineTools/SDKS/MacOSX10.14.sdk/usr/include/sys/_types/_null.h:30:
#define NULL
DARWIN_NULL
/Library/Developer/CommandLineTools/SDKS/MacoSX10.14.sdk/usr/include/sys/_types.h:52:24: no
#define _DARWIN_NULL ((void *)0)
2 warnings and 3 errors generated.
[Done] exited with code=1 in 0.108 seconds
[Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread0.c -o thread0 && "/
In main: creating thread
This is worker_thread()
[Done] exited with code=0 in 0.298 seconds
Transcribed Image Text:A Get Started D O ... C thread0.c x Volumes > RVPELLEGRINO > MAPUA > CPE105 > WEEK2 > C thread0.c > O main() // thread0.c ww.A - #include <pthread.h> G... 3 #include <stdio.h> 4. #include <stdlib.h> void *worker_thread (void *arg) 7 { printf("This is worker_thread ()\n"); pthread_exit(NULL); 8 9. 10 } 11 12 int main() 13 14 pthread_t my_thread; 15 int ret; 16 printf("In main: creating thread\n"); ret = pthread_create(&my_thread, NULL, &worker_thread, NULL); if(ret != 0) { 17 18 19 printf("Error: pthread_create() failed\n"); exit(EXIT_FAILURE); 20 21 22 } 23 24 pthread_exit(NULL); 25 v E 6 O ^ x PROBLEMS OUTPUT TERMINAL DEBUG CONSOLE Code /Library/Developer/CommandLineTools/SDKS/MacOSX10.14.sdk/usr/include/sys/_types/_null.h:30: #define NULL DARWIN_NULL /Library/Developer/CommandLineTools/SDKS/MacoSX10.14.sdk/usr/include/sys/_types.h:52:24: no #define _DARWIN_NULL ((void *)0) 2 warnings and 3 errors generated. [Done] exited with code=1 in 0.108 seconds [Running] cd "/Volumes/RVPELLEGRINO/_MAPUA/CPE105/WEEK2/" && gcc thread0.c -o thread0 && "/ In main: creating thread This is worker_thread() [Done] exited with code=0 in 0.298 seconds
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY