Question: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

 1 2 3 4 5 6 7 8 9 10 11

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
/* * ===================================================================================== * * Filename: hello_world.c * * Description: This file demonstrates the use of POSIX threads - A hello world program * * Version: 1.0 * Created: 11/03/2020 07:50:04 AM * Revision: none * Compiler: gcc * * Author: ABHISHEK SAGAR (), * Organization: Juniper Networks * * ===================================================================================== */ /* * compile using : * gcc -g -c hello_world.c -o hello_world.o * gcc -g hello_world.o -o hello_world.exe -lpthread * Run : ./hello_world.exe */ #include  #include  #include  /* For working with POSIX threads*/ #include  /* For pause() and sleep() */ #include  /* For using Global variable errno */ /* A thread callback fn must have following prototypes * void *(*thread_fn)(void *) * */ static void * thread_fn_callback(void *arg) { char *input = (char *)arg; while(1) { printf("input string = %s ", input); sleep(1); } } void thread1_create() { /* opaque object, dont bother about its internal * members */ pthread_t pthread1; /* Take some argument to be passed to the thread fn, * Look after that you always paas the persistent memory * as an argument to the thread, do not pass caller's * local variables Or stack Memory*/ static char *thread_input1 = "I am thread no 1"; /* Return 0 on success, otherwise returns errorcode, all * pthread functions return -ve error code on failure, they * do not set global 'errno' variable */ int rc = pthread_create(&pthread1, NULL, thread_fn_callback, (void *)thread_input1); if(rc != 0) { printf("Error occurred, thread could not be created, errno = %d ", rc); exit(0); } } int main(int argc, char **argv){ thread1_create(); printf("main fn paused "); pause(); return 0; }

please do it in cygwin using unix

Create a homework solution document (.pdf) that contains the answers to the following questions: a. What does this code do? b. Why do we need to include stdio.h? c. Why do we need to include "pthread.h? d. How would you change this code so that it creates exactly 10 new threads after the main thread starts? e. How would you change this code so that the main thread dies before any new threads are created? f. What can be guaranteed about which printf calls happen in which order? g. Under what circumstances would the error on line 68 get printed out? Compile the code in hello_world_thread.c to create an executable called "hello_world_thread. Demonstrate that you have successfully compiled and run the code, either through a combination of texts and screenshots, or by creating a video. Add this proof to your homework solution document. Change the code so that it creates exactly 10 new threads after the main thread starts. Compile and run the code to show that you have done this successfully. Add this proof to your homework solution document. Change the code so that the main thread dies before it can create any new threads. Compile and run the code to show that you have done this successfully. Add this proof to your homework solutions document. Create a homework solution document (.pdf) that contains the answers to the following questions: a. What does this code do? b. Why do we need to include stdio.h? c. Why do we need to include "pthread.h? d. How would you change this code so that it creates exactly 10 new threads after the main thread starts? e. How would you change this code so that the main thread dies before any new threads are created? f. What can be guaranteed about which printf calls happen in which order? g. Under what circumstances would the error on line 68 get printed out? Compile the code in hello_world_thread.c to create an executable called "hello_world_thread. Demonstrate that you have successfully compiled and run the code, either through a combination of texts and screenshots, or by creating a video. Add this proof to your homework solution document. Change the code so that it creates exactly 10 new threads after the main thread starts. Compile and run the code to show that you have done this successfully. Add this proof to your homework solution document. Change the code so that the main thread dies before it can create any new threads. Compile and run the code to show that you have done this successfully. Add this proof to your homework solutions document

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!