Assuming you weregoing to use Figure11.16 as part of a larger program, describe whereyou might use pthread_testcancel(3) to enable the threads to abort processing early (because some part of this larger program will have a reason to cancel threads and continue with other processing).

What will be an ideal response?


Calling pthread_testcancel inside complong every time it is called would be excessive, because this function will be called many times by the sort library function. However, we can maintain a counter in thread-local memory,increment the counter inside complong,and use the counter to limit the number of times we call pthread_testcancel, to every 1000 calls (for example). Note that it would be a bad idea to call pthread_getspecific(3) inside complong every time it is called, because it is likely just as expensive as pthread_testcancel.Wecan’t change the signature of the complong function, because it is dictated by the sorting library.Toavoid the overhead of calculating which counter to increment, we need a different approach. A better idea is to use a different function for each thread, and hardcode the functions to use different counters. This avoids the runtime overhead at the cost of a sightly larger program. Wecould maintain an array of functions and counters, and pass the index of the array to each thread in a structure, which also contains the starting index of the number range to sort. This approach has the added bene?t that the counters can be used without the need for any synchronization, because each thread uses a different counter.

Computer Science & Information Technology

You might also like to view...

The ___________ HTML element can be used to add a hyperlink to the JSP.

a) p b) link c) h1 d) a

Computer Science & Information Technology

Match each mathematical symbols to the operation that is performed: I. + II. * III. / IV. ^ V. - A. Exponentiation B. Multiplication C. Subtraction D. Addition E. Division

What will be an ideal response?

Computer Science & Information Technology

A server has recently been configured as a network firewall. After the firewall was configured, users could no longer access a remote server. Which of the following, if properly configured on the firewall, will allow users to have secure access to the remote server? (Select TWO).

A. Allow TCP port 21 B. Allow TCP port 22 C. Allow TCP port 23 D. Allow TCP port 25 E. Allow TCP port 161 F. Allow TCP port 3389

Computer Science & Information Technology

For memory improvements, several forms of volatile RAM are becoming available or are under development. _________________________

Answer the following statement true (T) or false (F)

Computer Science & Information Technology