Slashdot Mirror


Apple's Grand Central Dispatch Ported To FreeBSD

bonch writes "Apple's Grand Central Dispatch, which was recently open sourced, has been ported to FreeBSD and is planned to be included by default in FreeBSD 8.1. Also known as libdispatch, the API allows the use of function-based callbacks but will also support blocks if built using FreeBSD's clang compiler package. There's already discussion of modifying BSD's system tools to use the new technology." The port was originally unveiled last month at the 2009 Developer Summit in Cambridge. Slides from that presentation are available via the Dev Summit wiki.

52 of 205 comments (clear)

  1. Bad Apple by 93+Escort+Wagon · · Score: 5, Funny

    Always taking from the open source community, and never giving back!

    --
    #DeleteChrome
  2. Multicore Enhancements!! :) by jpedlow · · Score: 5, Interesting

    My first question was "So...what does this do?" Apparently it is a more efficient way of scheduling threads on multi-core systems http://images.apple.com/macosx/technology/docs/GrandCentral_TB_brief_20090903.pdf apple's site says this: "Grand Central Dispatch (GCD) in Mac OS X Snow Leopard addresses this pressing need. It’s a set of first-of-their-kind technologies that makes it much easier for developers to squeeze every last drop of power from multicore systems. With GCD, threads are handled by the operating system, not by individual applications. GCD-enabled programs can automatically distribute their work across all available cores, resulting in the best possible performance whether they’re running on a dual-core Mac mini, an 8-core Mac Pro, or anything in between. Once developers start using GCD for their applications, you’ll start noticing significant improvements in performance. " So this seems good then.

    1. Re:Multicore Enhancements!! :) by Anonymous Coward · · Score: 2, Informative

      Ah, but the benefit of Grand Central is that you don't need to worry (as much) about thread synchronisation and message passing. Just give it the blocks of code that are independent of each other, collect the results, and you're done. Think of it as giving you a ready-made scaffold; sometimes, it's more efficient to build your own that matches your needs more closely, but usually, it's just simpler to use what's already there.

      In other words, the whole point of Grand Central is that you don't need to worry as much about the "boilerplate" code around threads, and can focus more on what the code actually needs to do. This is a Good Thing. If it doesn't fit your needs, nobody is forcing you to use it ... but if it does, it makes life a hell of a lot easier.

    2. Re:Multicore Enhancements!! :) by zn0k · · Score: 4, Informative

      While you certainly don't deserve a "Troll" rating, the real improvement GDC brings over current implementations of concurrency is that one central authority is aware of all GDC enabled applications, and can therefore make decisions with knowledge of the entire system load and its capabilities when spinning of threads. When you spin of threads independently in each app you have to guess what the rest of the system looks like. You also have to either guess, investigate or have the user configure the general capabilities of the system.

    3. Re:Multicore Enhancements!! :) by moosesocks · · Score: 5, Informative

      Ars Technica has a great overview of what GCD is, and why it's important.

      I haven't done much multithreaded programming in C, although this looks like an absolute godsend to those who do. Maybe someday we can actually have a modern desktop as responsive as BeOS was...

      The article also contains a bit of information about Apple's compiler strategy and refinements to the C language itself. Most of these have been open-sourced under a permissive license, which is pretty damn cool.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    4. Re:Multicore Enhancements!! :) by wootest · · Score: 5, Insightful

      GCD is far more encompassing than just spawning threads. It's mainly a library for task-based parallelization (my wording, not theirs) and has some other goodies in it as well.

      For starters, unless it's not apparent by now, just spawning a new thread to run every such job is too heavy. Scheduling a new GCD job (and all of them will get run on one of a bunch of thread pool threads) is on the range of tens of CPU instructions; on Mac OS X, where GCD originated, spawning a new thread steals away in the vicinity of one megabyte (I can't seem to find an exact number) just for various bookkeeping. That's a lot of setup; even if there's a lot of fat to cut there, the best solution is probably not to spawn a new thread every time.

      The API is also very neatly designed. Tasks can be created and added to groups or queues and run synchronously or asynchronously. Semaphores, queues and event sources (which will trigger the addition of an event handler to a queue automatically) can all be paused and resumed to more easily control the flow. Neat, especially combined with the creation of queues that you set up to just funnel work onto another queue.

      Add to that the existence of several global queues with varying priorities (corresponding to a set of worker threads at each priority) and the potential for smarts for a system that can see the entire picture with regards to load within the program and across the system. I don't know the extent to which such smarts exist already, but I think you'll agree that with more metadata available, such a scheduler would be better equipped than one fiddling with coarser-grained threads.

      So yeah, this is nothing like "just" spawning threads. (I've never worked directly with pthread; it may very well reuse threads, but it didn't look like it from the man page you referred to.) None of it, as far as I can tell, is Apple inventing something new and breakthrough, but it's still a damn good API with a good consolidated set of computationally cheap features whose level of abstraction solves problems.

    5. Re:Multicore Enhancements!! :) by Stratoukos · · Score: 5, Insightful

      Maybe someday we can actually have a modern desktop as responsive as BeOS was...

      BeOS was indeed very responsive, but it was also notoriously difficult to program for. Apple seems to have done a great job at creating a powerful framework, while keeping it easy enough to be actually used by the developers.

      --
      It may be 7 digits, but at least it's a semiprime
    6. Re:Multicore Enhancements!! :) by Just+Some+Guy · · Score: 5, Insightful

      Been there, done that on Solaris and Linux 10 years ago in plain old C. No magic required, just

      #include <pthread.h>

      and away you go.

      Piece of cake! Of course, you have no idea how many other processes are tossing threads at their workload and so have no idea if this is a great time to spawn another 8 to really load out the CPU or whether you should just spawn 2 and let some other processes have their time. That's what GCD buys you.

      --
      Dewey, what part of this looks like authorities should be involved?
    7. Re:Multicore Enhancements!! :) by Space+cowboy · · Score: 2, Informative

      Parent spouts bollocks. Simon.

      --
      Physicists get Hadrons!
    8. Re:Multicore Enhancements!! :) by Anonymous Coward · · Score: 4, Informative

      In your zeal to take one statement out of context, you missed the point of the framework. Using dispatch queues, I don't have to create threads, an expensive operation, and I don't have to agonize over performance profiles to determine the right number of threads to use. The operating system automatically maintains a global pool of worker threads based on available system resources, and you submit an asynchronous block of code which the system will assign to a thread and run for you based on current system state--that's what the "automatically distribute their work across all available cores" part means. Quite different from merely creating a pthread. Your code will run in an optimal number of threads for the system it's on, whether it's a Mac Mini Core Solo or an eight-core Mac Pro.

      You can even distribute the iterations of a for-loop across queues using dispatch_apply(). Imagine doing a lot of expensive work on items in a collection, automatically threaded for the cores of the system it's running on. Here's an intro to Grand Central Dispatch. The followup articles on the site are also recommended.

      The API to submit a block for asynchronous execution is very simple:

      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
              do_something_computationally_expensive();
      });

      Posting anonymously since my "bonch" account has been modbombed.

    9. Re:Multicore Enhancements!! :) by buchner.johannes · · Score: 2, Insightful

      So does Linux need that, do they think about implementing something similar, porting it or what is happening?

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
  3. Re:They should use clang instead of GCC by larry+bagina · · Score: 4, Informative

    Apple maintains their own gcc fork which supports blocks/closures.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  4. Re:Apple's Grand Central Dispatch Ported To FreeBS by larry+bagina · · Score: 3, Funny

    now it can die in parallel, optimized for the number of cores and other system activity.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  5. Re:Apple's Grand Central Dispatch Ported To FreeBS by Anonymous Coward · · Score: 2, Insightful

    Netcraft confirms it: This joke is dying.

  6. Re:Apple's Grand Central Dispatch Ported To FreeBS by omar.sahal · · Score: 2, Funny
    On September 9, 2005, *BSD was finally declared dead. The following obituary appeared in the Berkeley Observer:
    1. * BSD Obituary
    2. * BSD, 28, of Berkeley, CA died Monday, Sept. 19, 2005. Born July 3, 1976, it was the creation of a cluster of pot-smoking hippies who went to Illinois and came home with a reel of tape. Rather than smoke the tape, they uploaded it and hacked on it a little.
    3. * BSD was known for its C shell and early TCP/IP implementation. After being banished from UC Berkeley, it was ported to the x86 platform, where it fell into the hands of heavier pot-smokers who liked to argue. Soon, the project had splintered into 12 different Balkanized projects. Until its death, there was almost constant fighting in and amongst these groups, sometimes degenerating into out-and-out fistfights.
    4. * BSD is survived by its superior, Linux, as well as several commercial unix implementations. It may be missed by some who knew it, although most of them are said to be mere OS dilettante dabblers.
    5. A funeral will be held at 2 p.m. Thursday, Sept. 22, at the Berkeley Chapel on the UC campus, with interment to follow via the burning of the original *BSD tapes and scattering of the ashes over the San Francisco Bay. The Rev. Lou "Buddy" Stubbs will officiate.
    6. The family will receive friends from 7 to 8 p.m. Wednesday, Sept. 21, at the funeral home.
  7. No because they are different by SuperKendall · · Score: 3, Informative

    GCD is a mechanism to let one central authority dispatch threads across multiple cores, for all running applications (including the OS).

    The other two things you mentioned are ways for programs to more easily use multiple threads, but they are still threads under the main process and not centrally managed - so you have to decide blind how much of the system you can take for your threading needs.

    You can compare the Blocks syntax to ways those two systems specify work units to be done in parallel, but that is just a part of the story.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
    1. Re:No because they are different by 99BottlesOfBeerInMyF · · Score: 2, Insightful

      GCD is a mechanism to let one central authority dispatch threads across multiple cores, for all running applications (including the OS).

      er... isn't that what modern preemptive multi-tasking OSes already do?

      Sort of, but GCD is about what application developers can do. Using current development methods the average developer decides how many threads to spawn and the OS tries to give them all equal priority. Further if you break your app into too many threads performance drops because of management issues. If you break it into fewer threads than there are cores, cores sit idle.

      GCD lets app developers break up their app into chunks that can be threads or can be the same thread and let the OS decide how far to break it up and what to send to what core and what to send to the GPU. It basically lets developers who use good practices fire and forget apps and not have to really worry about profiling and optimization for cores.

    2. Re:No because they are different by norton_I · · Score: 3, Interesting

      GCD is a mechanism to let one central authority dispatch threads across multiple cores, for all running applications (including the OS).

      This is what most people talk about, and what is most obvious from the name, but it is not the interesting part of GCD.

      The interesting part of GCD is blocks and tasks, and it is useful to the extent which it makes expressing parallelism more convenient to the programmer.

      The "central management of OS threads" is marketing speak for a N-M scheduler with an OS wide limit on the number of heavyweight threads. This is only useful because OS X has horrendous per-thread overhead. On Linux, for instance, the correct answer is usually to create as many threads as you have parallel tasks and let the OS scheduler sort it out. Other operating systems (Solaris, Windows) have caught up to Linux on this front, but apparently not OS X. If you can get the overhead of OS threads down to an acceptable level, it is always better to avoid multiple layers of scheduling.

    3. Re:No because they are different by Darinbob · · Score: 2, Insightful

      Much of what the GCD descriptions seem is "let's compare this well designed system to a badly designed system, and by implication presume that all threading schedulers are also badly designed". Ie, the comment about how Mac OS wastes so much space for each thread is entirely irrelevant here, except to say that on the Mac OS itself you will get better performance with GCD for some situations. It says nothing about better designed threading systems (ie, on embedded and real time systems where no one is storing 512K for a mere thread). It's comparing light weight threads to heavy weight threads.

      It seems to solve the problem of what happens when you've got too much work for each processor is to make things more fine grained. Lots of tiny tasks spread around a few threads on just the right number of processors, rather than lots of threads. You've essentially just got a scheduling problem, you can have an academic career doing this stuff. Figuring out which sets of tasks have priority over others is not that much different than figuring out which applications threads have priority over other threads (ie, is the app with 6 threads more important than the one with 4 threads if you've only got 8 processors).

      Splitting threads into smaller chunks, if you can rearrange your app structure is one approach to this. Your long running threads that talk to each other are now split into smaller units that talk to each other, only you've got more ways to arrange them. Essentially you're going from very coarse grained parallelism to a finer grained parallelism. which gives more flexibility. But people have been doing this stuff and dealing with its problems for decades. You run into the dusty deck problem again, only in a more modern context. Ie, you tell customers you can speed up their code on your parallel machine and compiler by a factor of X, only they have to rewrite things somewhat, and most customers find that too difficult or their algorithm isn't easily parallelized.

    4. Re:No because they are different by kojot350 · · Score: 2, Informative

      Guess where they got this idea...

      --
      [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*
  8. GCD is not multithreading, it's thread management by diamondsw · · Score: 5, Informative

    Grand Central is not introducing multithreading - it's introducing comprehensive thread management. So, how many threads are you going to spin for that task? Too many, and you waste a lot of time on thread management and preemption. Too few, and you have processors sitting idle. Now how will you handle this with multiple CPU's? Multiple cores? Hyperthreading? Different cache amounts and layout? OpenCL and GPU processing? Do you know what the rest of the operating system is doing to plan appropriately?

    In short, your program can at best make a stab at these issues, and possibly even do a reasonable job if you put a lot of time, effort, and profiling into it. Or you could just use GCD, and let the framework handle it all for you, regardless of whether you're on a Core Solo Mac Mini or a Mac Pro with mutliple OpenCL graphics cards.

    It's good stuff. And Apple gave it to the community (much like WebKit enhancements, launchd, etc).

    --
    I don't know what kind of crack I was on, but I suspect it was decaf.
  9. Re:OpenMP by fred+fleenblat · · Score: 2, Interesting

    it seems like the ability to share work across machines, not just cores, would be a critical difference.

  10. Re:In other news... by wootest · · Score: 5, Funny

    Richard Stallman does not cry into his beer. Microsoft cries into their beer. Richard Stallman cries into his freedom.

  11. Re:No. Really? by beelsebob · · Score: 5, Informative

    Yep, apple didn't give back all their code on WebKit, or all of Darwin, or all of launchd, or all their patches on zfs, or their code on MacPorts, or darwin streaming server, or CalDav, or iCal format, or their Calander server, or their code on their X server, or their code on ruby, or a bunch of code on smart card services...

    Wait, yes they did.

  12. Thank goodness for the GPL by Anonymous Coward · · Score: 4, Funny

    Thanks goodness for the GPL, or we might never have convinced Apple to release its code so that FreeBSD could use it!

    Wait... what is that? Oh, nevermind then...

    1. Re:Thank goodness for the GPL by TheRaven64 · · Score: 3, Informative

      Clang is BSD licensed and, unlike GCC, supports blocks on FreeBSD and Linux, as long as you have the relevant runtime library. Etoile has been shipping one (MIT licensed) for about six months. Libdispatch is new code from Apple and is Apache 2 licensed, which is incompatible with the GPLv2 (GPLv3 has a special exemption for it).

      --
      I am TheRaven on Soylent News
  13. Re:In other news... by Neurotic+Nomad · · Score: 2, Funny

    "Freedom" is what he calls his beard.

  14. you're imagining things by jipn4 · · Score: 2, Informative

    it seems like the ability to share work across machines, not just cores, would be a critical difference.

    Neither GCD nor OpenMP allow you to "share work across machines".

    1. Re:you're imagining things by AHuxley · · Score: 2, Informative

      yes Apples has Xgrid to 'share work across machines".
      http://en.wikipedia.org/wiki/Xgrid

      --
      Domestic spying is now "Benign Information Gathering"
  15. Re:Apple's Grand Central Dispatch Ported To FreeBS by Anonymous Coward · · Score: 2, Informative

    On their stolen computer next to all the other things they stole from school. They even steal the flies from outside who swarm around their unwashed bodies. linux is the devolvement of humanity - a linux user is like an anti-human - taking the opposite form of what a real human should be. They do not know how to reproduce, they cannot interact with others and they long ago forgot the concept of personal hygiene. They believe communism is something we should strive for and believe klingon is a real language. yes... we know of your type.

  16. Re:In other news... by harlows_monkeys · · Score: 2, Informative

    The key here is the code behind grand central dispatch is not GPL compatible [arstechnica.com], so Linux will probably never get this code

    That's not quite correct. There are two parts to GCD: libdispatch and the kernel support. The kernel support is MIT license, so is compatible with GPL. Besides, the kernel component wouldn't be ported anyway--it would be rewritten from scratch if one were doing GCD Linux, so the license doesn't matter.

    Libdispatch is Apache license. It runs in the applications, not the kernel, so the kernel being GPLv2 is irrelevant. What's relevant are the licenses of the applications that might want to use libdispatch. Many of those will be licensed as GPLv2 or later. Those are OK, because Apache license is compatible with GPLv3.

    Finally, if libdispatch were to be included as a standard part of Linux, even GPLv2 code could dynamically link to it, because it would fall under the system library exception.

  17. Re:No. Really? by zach_the_lizard · · Score: 3, Informative

    Yes, WebKit is based on KHTML; Apple forked it, IIRC.

    --
    SSC
  18. Re:GCD also replaces most synchronization / lockin by setagllib · · Score: 2, Insightful

    If you're creating a serial queue anyway, you no longer have parallelism. If you have multiple serial queues, you may as well have had multiple threads with no interlocking between them. This is just yet another API to do what competent parallel system programmers have been doing since the first thread.

    --
    Sam ty sig.
  19. Re:No. Really? by DurendalMac · · Score: 4, Insightful

    Several things didn't need to be open sourced, such as WebObjects and GCD. Quit your crying. FOSS zealots love to whine about Apple only doing what's required, but they fail to realize that it's a symbiotic relationship. Apple can use existing code to fit their needs, and in return, the open source community gets all of the improvements made by professional coders. It's a win/win, but the mini-Stallmans will never see it that way.

  20. Re:They should use clang instead of GCC by bill_mcgonigle · · Score: 2, Interesting

    Apple maintains their own gcc fork which supports blocks/closures.

    why won't gcc take the patches?

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  21. Re:They should use clang instead of GCC by Anonymous Coward · · Score: 2, Informative

    Because Apple is sticking with GPLv2

  22. They are not mini-stallmans. They are Apple Haters by SuperKendall · · Score: 4, Interesting

    It's a win/win, but the mini-Stallmans will never see it that way.

    To the contrary: I am a huge fan of Stallman's philosophy and see Apple's work as win/win.

    The people that are complaining are the looney Apple Haters, who try and find any point possible by which to attack Apple - never realizing until it is to late the latest position they are attacking from makes no sense.

    Please do not taint all those of us who respect the GPL with the same brush the Haters paint themselves in corners with.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  23. Re:What is the deal with clang? by LenE · · Score: 2, Informative

    It will support C++ soon enough.

    The benefits of clang are that it uses llvm as the compiler, which produces better optimized machine code than gcc currently does. Also, it supports Apple's block syntax (kind of like a pointer to a function), which allows things like libdispatch to do its magic. Also, as a C front end, it has much less cryptic error messages, and actually does a pretty good job of finding missed initializations and other hard to find bugs that usually will get caught at the code execution stage.

    You should check out Siricusa's more thorough explanation at arstechnica, in his Mac OS X 10.6 Snow Leopard review. He goes into some detail to show how Apple's use of clang in the new XCode is almost "pornographic for developers..." You wouldn't have the same IDE in BSD or Linux, but the same functionality is there. Someone posted a link much higher in the thread.

    -- Len

  24. Re:No. Really? by Jerry+Smith · · Score: 3, Insightful

    When is the last time that Apple released an entirely new project? For example Sun released ZFS under the CDDL.

    Why reinvent the wheel? They adopt it, improve it and release the improvements. At least they add. They deliver. When is the last time Stallman released an entirely new project? Or finished one? "Although nearly all components have been completed long ago and have been in production use for a decade or more, its official kernel, GNU Hurd, is incomplete and not all GNU components work with it." from the reliable-as-ever Wikipedia. Apple is not Stallman. They do not serve the same market. Apple is in hardware/software/platform, Stallman is in philosophy. Fair enough, einen Unterschied muß es geben.

    --
    All those moments will be lost in time, like tears in rain. Time to die.
  25. Re:They should use clang instead of GCC by jcr · · Score: 3, Interesting

    The probability that Apple migrates away from gcc is approaching 1 at great speed.

    That writing's been on the wall for quite a long time now. GCC has been a severe limitation on what they could do with Xcode for far too long. With LLVM, I'm expecting shortly to get away from the edit/compile/debug cycle and have a pause/edit/resume cycle instead.

    Right now in Quartz Composer, you can write GL SLANG shaders that are compiled on the fly as you type. It's amazing to see the effects of changes immediately.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  26. Re:GCD also replaces most synchronization / lockin by jcr · · Score: 2, Insightful

    This is just yet another API to do what competent parallel system programmers have been doing since the first thread.

    RTFM, and learn what you're missing.

    The point of GCD is that taking advantage of multiple cores becomes much less work. When I say "much less", thinks minutes versus days. Besides the ease of use, the underlying implementation also deals with scaling the queues across the number of available cores on the fly, and makes the management of serial dependencies trivial.

    Another benefit of GCD over managing the threads yourself is performance. Apple changed the implementation of Objective-C's garbage collector from running on a dedicated thread to running in GCD, and picked up a double-digit improvement in the speed of memory recovery.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  27. Re:No. Really? by gutter · · Score: 3, Insightful

    Well, we have the subject of this article, Grand Central Dispatch. We also have Darwin & XNU, their version of the Mach kernel. There is also Bonjour, their version of zeroconf, and their streaming server (Quicktime Streaming Server). They also purchased the source to gimp-print (now called Gutenprint) so they no longer have any obligation to keep it open source, but they do, and they keep releasing the source. How much more do you need?

    --
    Check out DRM-free movies at http://www.bside.com
  28. You're missing the point by Gary+W.+Longsine · · Score: 2, Informative

    Apple isn't "sticking with GPLv2" so much as "actively working to replace every last scrap of GPLvn code with BSD/MIT/Apache code." They appear to be under the impression that GPL is unfriendly to business, which impression is defensible. They are investing many programmer years in Clang/LLVM, and soon enough will be liberated from the tyranny of gcc.

    --
    If you mod me down, I shall become more powerful than you could possibly imagine.
  29. Re:No. Really? by Anonymous Coward · · Score: 3, Funny

    But apart from CUPS, LLVM/clang, Webkit, Darwin, launchd, patches for zfs, MacPorts, darwin streaming server, CalDav, iCal, the Calendar server, code for Ruby, code for X server and GCD, what has Apple ever done for us?

  30. Re:No. Really? by RichiH · · Score: 2, Informative

    Webkit is kinda special. For ages, Apple did nothing other than releasing the full source every time they released binaries.

    They did _not_ release anything under SCM control, which meant tracking patches etc was _literally_ impossible for the KDE team. No matter what the KDE team did or how often they asked, this did not change. This is a large part of why KHTML and Webkit are as different as they are now. Using both KHTML and the Webkit Kpart in KDE 4.3.2, I can tell you that there are a lot of little differences in rendering and, that is where it hurts, usability. Sucks.

    So while Apple followed the letter of the license, they went against its spirit in every possible way for a long time. This may have changed somewhat (iPod, iTunes...?), but one should be aware of the history.

  31. Re:They should use clang instead of GCC by TheRaven64 · · Score: 4, Informative

    A massive case of NIH from the GCC team with regard to Apple. See also the patches that Apple submitted well over a year ago adding declared property support to GNU gcc. I found it easier to write all of the code required for clang to support the GNU Objective-C runtime than make even small changes to Objective-C support in GCC (in spite of not having used C++ for a few years and really hating the language).

    Oh, and I've had blocks working with clang on FreeBSD for quite a while (since several months before Apple publicly released an OS supporting them, in fact). I added the required runtime library support into Etoile's ObjectiveC2 framework a while ago, which also provides the run time support for most of the Objective-C 2 features. This framework is going to go away soon, because I'm now maintaining a fork of the GNU Objective-C runtime in the GNUstep repository, which merges these improvements and also incorporates most of the ideas from my experimental Objective-C runtime library (without breaking backwards compatibility, although you don't get all of the features if you don't use the new ABI).

    By the way, porting to *BSD is much easier than porting to Linux. Libdispatch is based around the kqueue mechanism for unifying kernel event sources, and there is currently no in-tree equivalent for Linux. There are four out-of-tree sets of patches providing equivalent functionality (that I know of, there may be more), as is common with Linux development. On Solaris you can do the same thing with completion ports, which are roughly semantically equivalent but have a different interface.

    --
    I am TheRaven on Soylent News
  32. Re:No. Really? by mi · · Score: 2, Funny

    Where do you think they got the code from in the FIRST PLACE????

    From the professional coders at AT&T?

    (ducks...)

    --
    In Soviet Washington the swamp drains you.
  33. Re:That is more interesting but not what is differ by TheRaven64 · · Score: 3, Informative
    Thread creation on Linux is much more expensive than adding a new block to a queue with GCD. This uses 'under 15 instructions'. That's slightly misleading because, on x86, one of those instructions has the LOCK prefix and so is quite expensive, but it's still only marginally more expensive than the cost of a function call. In contrast, creating a thread, at minimum, on Linux has these costs:
    • Allocate at least one page for the stack.
    • Allocate at least one page for the TLS segment and copy its data across.
    • Create the in-kernel data structures required for the thread and insert it into the run queue (this involves a context switch into kernel space and back).

    This is between one and two orders of magnitude more expensive than adding a block to a work queue with GCD.

    Switching between the threads is also relatively expensive. At the very least, you need to save all of the registers and update the stack pointer (probably in response to a timer interrupt, so also factor in the cost of a transition from kernel space to users pace). With GCD, the kernel will give you one thread per CPU for each priority level (or fewer if there are already lots of CPU-bound threads), so you minimise number of context switches.

    This is effectively what an N:M scheduler does, but is slightly better. With an N:M scheduler, you are switching between some threads in userspace, which saves some overhead, but the threads still have largely-disjoint working sets and so you end up with more cache churn (performance killer on modern CPUs). With GCD, you will only be switching between work queues in a given thread between blocks, so there is no cache churn (the old block's cache lines are no longer needed, so you'll kick them out but not then bring them back in immediately). The other nice side effect of this is that, because GCD knows which work queues are assigned to which threads, it can remove locks used for passing messages between work queues if both queues are in the same threads.

    In short, it's an N:M threading model with preemptive kernel threads and cooperative userspace threads. If you read an OS textbook, you'll see that this is, at least in theory, about the most efficient scheduling model possible.

    --
    I am TheRaven on Soylent News
  34. Re:No. Really? by beelsebob · · Score: 2

    Uh, yes? Sure, you *made* them give up their source if they used your project, but that doesn't change the fact that they *did* use your project, and then contribute back hundreds of thousands of improvements. Or are you suggesting that khtml without apple's assistance would be in the position WebKit is now?

  35. Re:No. Really? by beelsebob · · Score: 2, Insightful

    In the mean time... When is the last time that Apple released an entirely new project?
    You do realise this article is *about* apple releasing the source code to libdispatch?

  36. Re:They should use clang instead of GCC by Shinobi · · Score: 2, Interesting

    It goes further and deeper(and uglier) than that. Remember when Apple released the G5's? Apple actually submitted patches to GCC, but they were declined, with GCC's official stance being "It would reduce GCC's portability". However, a few weeks later, IBM submitted some patches for GCC, that were summarily accepted. IBM's patch package contained many of Apple's patches for GCC.

  37. Re:GCD is not multithreading, it's thread manageme by petermgreen · · Score: 2, Insightful

    when we start using octal cores
    High end workstations are already shipping with dual quad (8 cores total) and will probablly be shipping with dual hex (12 cores total) in the not too distant future. Quad core is fairly common in the midrange and is even available on some fairly low end machines (e.g. the dell vostro 420). Laptops and low end desktops are generally shipping with dual cores.

    With the exception of nettops and netbooks single cores are pretty much history.

    The bottom line is that cores aren't getting that much faster so most of our gains in computing power are likely to come from more cores and software that needs to get the most out of CPUs is going to need to embrace that and soon.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register