Could Grand Central Dispatch (`libdispatch`) ever be made available on Windows?
Asked Answered
S

5

17

I’m looking into multithreading, and GCD seems like a much better option than manually writing a solution using pthread.h and pthreads-win32. However, although it looks like libdispatch is either working on, or soon going to be working on, most newer POSIX-compatible systems… I have to ask, what about Windows? What are the chances of libdispatch being ported to Windows? What are the barriers preventing that from happening?

If it came down to it, what would I need to do to preform that portage?

Edit: Some things I already know, to get the discussion started:

  • We need a blocks-compatible compiler that will compile on Windows, no? Will PLBlocks handle that?
  • Can we use the LLVM blocks runtime?
  • Can’t we replace all the pthread.h dependencies in userspace libdispatch with APR calls, for portability? Or, alternatively, use pthreads-win32 I suppose…

Edit 1: I am hearing that this is completely and totally impossible, ever, because libdispatch depends (somehow) on kqueue, which can’t be made available on Windows… does anybody know if this is true?

Somersomers answered 2/5, 2010 at 2:51 Comment(5)
You seem to insist that a Windows port must be a source level port. It doesn't - the implementation can be completely different, while maintaining the same APIs. For example, a thin wrapper around one of the Windows technologies I mentioned in my answer would not require pthread, PLBlocks, LLVM, kqueue or any other such component that sound to me like the names of undecipherable Hungarian-notated struct pointers.Bertrand
Well, I don’t want just the API… I want the benefits of GCD itself, if slightly less performant due to the lack of kernel‐level optimization. If these pre‐existent Windows technologies are up to snuff, then why haven’t I heard any buzz about them pre‐GCD?Somersomers
"Buzz"? Srsly? Is that what you're looking for? In any case, they are rather new (or more precisely, they've only gone gold recently), and I don't know about you, but I'm hearing plenty of buzz about them. If Google search result count is any indication of "buzz", compare bit.ly/dk4ry9 to bit.ly/9138DV or a BlogPulse 6-months comparison: bit.ly/9L3VtMBertrand
Five ORs vs. one d-; But, in any case, interesting. Perhaps that’s a possible solution; at the very least, it’d be neat to see a libdispatch API wrapper around those.Somersomers
True, it has many names for practically the same thing, and I didn't know what other ORs to add for the GCD (the acronym itself brings in a lot of unrelated junk). And yeah, it would be interesting to see a wrapper, for both directions.Bertrand
A
8

Take a look at : http://opensource.mlba-team.de/xdispatch/ This project (and other third-party libs) brings libdispatch into platforms(windows, linux) other than macosx

Atharvaveda answered 30/7, 2013 at 16:45 Comment(1)
Wow, great find! (Bringing a little more information from their various pages into your answer here would win you another upvote, as well as the accept. Perhaps a summary of how to use it, copied from their page; and a list of platforms across which the approach is known to work? =)Somersomers
S
8

https://github.com/DrPizza/libdispatch

Smug answered 24/6, 2011 at 8:22 Comment(1)
Great work and blog posts as well. There has been no updates since a few years ago. Is it still functioning?Arian
A
8

Take a look at : http://opensource.mlba-team.de/xdispatch/ This project (and other third-party libs) brings libdispatch into platforms(windows, linux) other than macosx

Atharvaveda answered 30/7, 2013 at 16:45 Comment(1)
Wow, great find! (Bringing a little more information from their various pages into your answer here would win you another upvote, as well as the accept. Perhaps a summary of how to use it, copied from their page; and a list of platforms across which the approach is known to work? =)Somersomers
B
5

The Windows equivalent of libdispatch, from my basic understanding of it, is the Concurrency Runtime for unmanaged code and a collection of technologies collectively known as Parallel Extensions for managed code. It appears to me that GCD maps pretty well to both of these, since they both abstract work units (or "tasks") in a similar way.

Bertrand answered 2/5, 2010 at 11:14 Comment(3)
yes these are the equivalent technologies. blogs.msdn.com/nativeconcurrency is the team blog for the Concurrency Runtime and blogs.msdn.com/pfxteam is the .NET team blog.Nimitz
Is this available to C++?Arian
@Arian Yes, the Concurrency Runtime is for C++11: learn.microsoft.com/en-us/cpp/parallel/concrt/…Bertrand
A
1

From a bit of research, it appears that there's already a fair bit of interest in a port, but that port would be a fairly drastic undertaking and might end up being basically just another implementation of the API and not actually sharing significant code with the original libdispatch. I did see some proposals to porting libdispatch to being based on the Apache Portable Runtime instead of POSIX which'd make it easier to make it cross-platform to Windows, but even this would not be an easy change.

Likely, this would be by no means a small undertaking.

Anthill answered 2/5, 2010 at 3:0 Comment(1)
If for such a library you really think about adding another portablility layer you are a very bad programmer, any approach to a libdispatch would be barebone.Timeous
B
1

I think that rather than libdispatch-on-pthreads and pthreads-on-Win32, or libdispatch-on-APR and APR-on-Win32, it might be better to implement libdispatch directly on the Win32 Thread Pool API. The good news is that the two APIs are similar enough that you could probably do the port yourself. The bad news is that there would probably be lots of corner cases where there are small semantic mismatches that make exact behavior hard to achieve.

Bosky answered 2/5, 2010 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.