Reimplement Exercise 4.11 to use multiple threads. Because the current working directory is a process attribute, it is shared by all threads, so you can’t use chdir(2). Instead, use the *at functions to allow 16 worker threads to process different parts of the ?le system at the same time. How much faster is this version compared to the version from Exercise 4.11?

What will be an ideal response?


Because the user-de?ned function passed to ftw is passed a full pathname, we must maintain the absolute pathname, so we really don’t need to use any *at functions. But that would be no fun, so we’ll use fstatat(2) instead oflstat(2). With multiple threads, we need to protect the data structures that the threads access. Weuse a mutex to protect the list of directories to scan, and a condition variable for the threads to wait for work. We also use a spin lock to protect the counters we keep for the ?le types we encounter.The main thread starts things offand then waits for the worker threads to complete. The solution is shown in Figure33. When comparing its performance to that of the program from Exercise 4.11, you should ?nd that Exercise 4.11runs in less user time and less system time, but with moreelapsed (clock) time. ![12522|458x392](upload://9ggzPvP6UrrgjlNwzJs6H0EW7FR.png)
![12523|378x500](upload://8JJzdHFlYZmPU8cZlOT3RgKiqqp.png)
![12524|336x500](upload://xWz2NtaQ0C9LPBIYwjItd9NxX1X.png)![12525|349x500](upload://wqNC2Cm2C9SdAl0ua7HLgoOw2uY.png)
![12526|353x500](upload://dGk3q1ow7yqOt0sfELKen7nziFQ.png)
![12527|482x228](upload://d58Yu9lQn8pKdxUvuOXzd3RdfoL.png)

Computer Science & Information Technology

You might also like to view...

A ________ is a series of characters that fill in the gap between two tabbed items. in Word

A) leader B) character C) stop D) path

Computer Science & Information Technology

Case-Based Critical Thinking QuestionsCase 7-2Kyra is quizzing her friend Leon about the various options available in CSS to direct parts of the Web page to different output devices, in preparation for his test tomorrow.Kyra asks Leon how she can view a likeness of the print style. What is his answer?

A. Print the page. B. Use the print preview feature in the browser. C. Use the set print options feature. D. all of the above

Computer Science & Information Technology

Which part of the Ethernet address is assigned to vendors to identify the equipment manufactured by them?

A) First two bytes B) Last byte C) First three bytes D) Last three bytes E) Second and third bytes

Computer Science & Information Technology

Match the term with the correct item below. (Not all Terms are used.)

A. A _______________ is provided to a potential employer to assist in checking your qualifications. B. C. A resume in a Word document attached to an e-mail is an example of a(n) __________. D. A keyword search uses  __________ to match keywords. E. F. G. H. To determine the specific qualifications required for a job that is available, review the  __________. I. A(n) __________ is used to determine which companies may be the best prospects for your job search. J.

Computer Science & Information Technology