Skip to main content

Grand Central Dispatch for Android?

(Sometimes after a couple of hours of research, the result is a dead-end or needs further digesting.
Still, such a result might itself still be worth remembering.
This is a Quick&Dirty report of one of those cases.)

GCD is an implementation of thread pools / queueing (+ event management (sockets, files), etc) by Apple for Mac OS X / iOS. It was open-sourced, and FreeBSD got an implementation. They are practically an abstraction and simplification over pthreads (+ events, etc), and the GCD implementation includes some kernel and compiler changes (workqueues and blocks, respectively). Implementation details at http://newosxbook.com/articles/GCD.html. It's well performing and seemingly can help simplifying a lot.

What if one wanted to use GCD in Android? Is there anything compatible enough and that could be used at the C level?

Assuming that Android is a Linux ;P, then we can start with the fact that Linux doesn't seem to have any official GCD-like thingie. However, there are a couple of GCD ports, which do not seem to use anything kernel-level, and only optionally take advantage of compiler support for blocks- which anyway should be available in Clang, maybe even in GCC.
https://github.com/nickhutchinson/libdispatch
https://github.com/mlba-team/xdispatch (even for Windows!)


Comments

  1. I comment because even in 2019 this comes up as a top result for "Grand Central Dispatch Android" searches. The main problem is that the Unix guys don't understand the genius of GCD and that it is much more then pthreads.

    Its giving the kernel scheduler the power to create and destroy threads inside a program based on overall process/thread usuage patterns. Thats a huge thing. It can't be ported to Linux or Android or only with very low quality - and low quality in parallelism can destroy all benefits.

    There is also no other mechanism available on Linux and maybe also not on Windows (but i don't know what MS added since Windows 10).

    ReplyDelete
    Replies
    1. Interesting, thank you. Thankfully not all "Unix guys" are so blind, after all FreeBSD has its port, right? ;)

      You say it can't be ported to Linux... but why? In other cases, Linux seemed to end up getting some late but arguably competitive alternative to the new developments in the other Unixes (ZFS -> BTRFS, DTrace -> eBPF). Of course BTRFS is still not fully there yet, and eBPF took some time and false-ish starts... I wonder what's the status regarding the GCD angle.

      Delete

Post a Comment