Grand Central Dispatch goes Open Source
Posted: Fri Sep 11, 2009 12:37 pm
Apple has open sourced the Grand Central Dispatch library as libdispatch under the Apache 2.0 license. GCD provides a way to make parallel programming very easy for developers and is most useful for the C family of languages. It combines a proposed concept in C called blocks (or closures) which are somewhat similar to function pointers (for use with callbacks) and make functional programming a lot easier. These blocks are then passed to GCD which can queue synchronous and asynchronous blocks that will be then be executed by threads. GCD provides all the thread handling and management. It is close enough to the metal that it is aware of the number of cores on the system and how many are in use and will created threads appropriately. (Multithreading is difficult because the number of threads that an app should optimally use depends on the run time availablity of cores.) Mac OS X 10.6 gains a lot of performance benefits from using GCD built into the operating system. Now that technology has been made open source which has some interesting reprecussions. It means that people have an incentive to port the library to other systems (particularly servers and research machines). It also means that people are more likely to use blocks in the C language which is not part of the standard (but may become standard if it becomes widely used). Also because the Apache license is not copyleft, this technology may appear in unexpected closed source products as well. In any case, this is very interesting tech and nice to see it made open source.
Official site: http://libdispatch.macosforge.org/
Some more reading on blocks and the GCD from Ars Technica (highly recommended):
C Blocks
GCD part 1
GCD part 2
Note: interesting tid bit about blocks is that a similar functionality has been proposed in C++0x as lamda functions. Both C++ and C are in the process of being updated to new standards. C++ has had a lot more work done on it but Apple has a vested interest in advancing C since their primary language Objective-C is a superset of C and would gain no benefit from advances in C++.
Official site: http://libdispatch.macosforge.org/
Some more reading on blocks and the GCD from Ars Technica (highly recommended):
C Blocks
GCD part 1
GCD part 2
Note: interesting tid bit about blocks is that a similar functionality has been proposed in C++0x as lamda functions. Both C++ and C are in the process of being updated to new standards. C++ has had a lot more work done on it but Apple has a vested interest in advancing C since their primary language Objective-C is a superset of C and would gain no benefit from advances in C++.