Copy of Topic10-Threads

.pdf

School

University of Massachusetts, Amherst *

*We aren’t endorsed by this school

Course

230

Subject

Computer Science

Date

May 5, 2024

Type

pdf

Pages

7

Uploaded by MasterCrown14278 on coursehero.com

Working with Threads Forming Group Start time: In this activity, you work in teams of 2~3 students to learn new programming concepts. Content Learning Objectives 1. Understand the thread functions. 2. Learn how to identify critical zones and race conditions. 3. Learn how to use semaphore.T Role Name Project Manager : reads the questions aloud, keeps track of time and makes sure everyone contributes appropriately. 1. Clicks on FILE-> MAKE A COPY 2. Shares the copy with all the other team members using their UMass email address Lucky Kovvuri Recorder : records all answers in the Google doc shared by the Manager and ensures the team agrees on responses. Hacker : type the code and execute. Please assign the page number for each question, otherwise, you will receive 0.1 deduction for each question.
(15 min) Activity 1. Thread and Process Start time: Take a moment to read through the manual of pthread_create(3) , pthread_join(3) , and pthread_self(3) . This manual page describes the pthread_create function which creates a new “thread” of execution. There is a fundamental difference between processes and threads. Q1. Talk with your group about what you read in the documentation for these three functions. Provide in the answer box below any notes from the manual page that are interesting to you. Answer: pthread_create(3) – was interesting that the new thread inherits the calling thread’s floating point environment pthread_join(3) – the results are undefined if multiple threads try to join with the same thread at the same time pthread_self(3) – it always succeeds and returns the calling thread’s ID Q2. Explain in the answer box below how each of the thread functions you reviewed in Part 1 relate to fork(2), waitpid(2), and getpid(2). What is the difference between the two sets of functions? More specifically, match each of the above functions with one from fork, waitpid, getpid according to which they are fundamentally most similar to, then mention how they are similar and how they are different. Answer: pthread_create(3) relates to fork(2): the first creates a new thread and the other creates a new child process. fork returns the pid of the child process in the parent process, but pthread_create(3) stores the thread-id of the newly created thread in argument passed into its “pthread_t *thread” parameter pthread_self(3) relates to getpid(2): pthread_self() obtains the ID of the calling thread in a multi-threaded program; getpid() gets the ID of the calling process in a multi-process or single-threaded program pthread_join(3) relates to waitpid(2): both reap threads/child processes. waitpid() can only be called in the parent process; pthread_join(3) can be called from any thread to any thread in same process
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help