Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ignore d and e since they're more so statements rather than actual questions. Here's the program written in C that the assignment is based off
Ignore d and e since they're more so statements rather than actual questions. Here's the program written in C that the assignment is based off of:
4. Answer the following questions: a. In Pthreads programs, global variables are shared among all threads; each thread has a private copy of local variables and function arguments. What variables, if any, are shared in pth_hello? b. What do you think strtolo) does? c. Why do you have to call malloc function in the program? d. Now look at the loop that creates the threads. The first argument is a pointer to a pthread_t object. This is an opaque object that is system dependent. The second argument has to do with thread attributes and we will pass NULL. The third argument is the target function that the thread will execute. There is some trickery going on with the fourth argument. First, we are giving the thread a rank because we can't use pthread_t to identify threads (although the operating system can). We are passing an integer but telling the function that it's a pointer; the create function wants a pointer because it expects a list of arguments. In the function, we cast the argument to a long int. This could cause a problem if the pointer type is a different size than the type of the argument-that's why we use long. On some systems and int is 32 bits but a pointer is 64 bits. A long int should be 64 bits on those systems. e. Note that we don't explicitly have to start the threadsthe create function does that. f. The value of my rank for thread 3 is g. What do you think pthread_join() does? h. What do you think free() does? We should have been calling free() in our previous programs that use malloc but I've gotten so used to languages that do garbage collection that I often forget. #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started