Question

In: Computer Science

Various libraries, like pThread.h (and its associated library) in C, give languages exposure to the underlying...

Various libraries, like pThread.h (and its associated library) in C, give languages exposure to the underlying system’s threading system. How does working with Grand Central Dispatch differ from other threading systems you have used (if you have never used threading, read up on Java threading for a comparison)? Be sure to talk about the activities that take place on the main thread versus those that take place on the background threads.

Solutions

Expert Solution

Grand Central Dispatch(GCD) and other threading systems are both designed to encapsulate units of work and send them for execution. One of the most used threading system is NSOperation , it is an objective-C API and it brings with it some overhead.

After the introduction of GCD Apple refactored NSOperation to work on top of GCD.

GCD is low level-C API that directly interacts with Unix level of the system.

In case you are using NSOperation then you are implicitly using GCD.

GCD is ideal if you have to send off a block of code to a serial or a concurrent queue. Benifit of using Grand Central Dispatch is that you can keep all the related codes together.

In GCD the kernel threads/ background threads are preemptive and the user threads/main threads are cooperative.User space threads are multitasking threads and can give better throughput but the disadvantage is that it can kill the responsiveness of the entire system. GCD can solve this by spawning some extra kernel threads if the user space threads are not completing blocks fast enough.


Related Solutions

Describe at least two potential problems associated with an over-reliance on various performance measures like profitability,...
Describe at least two potential problems associated with an over-reliance on various performance measures like profitability, stock price, or market share.
Please, write code in c++. Using iostream library Most modern text editors are able to give...
Please, write code in c++. Using iostream library Most modern text editors are able to give some statistics about the text they are editing. One nice statistic is the average word length in the text. A word is a maximal continuous sequence of letters ('a'-'z', 'A'-'Z'). Words can be separated by spaces, digits, and punctuation marks. The average word length is the sum of all the words' lengths divided by the total number of words. For example, in the text...
C language Write a program in C to implement Queue and its operation (like create, insert,...
C language Write a program in C to implement Queue and its operation (like create, insert, delete, search) using array data structure.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT