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?

Gabe
  • 84,912
  • 12
  • 139
  • 238
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
  • 3
    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. – Allon Guralnek May 02 '10 at 20:24
  • 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? – ELLIOTTCABLE May 02 '10 at 22:51
  • "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 http://bit.ly/dk4ry9 to http://bit.ly/9138DV or a BlogPulse 6-months comparison: http://bit.ly/9L3VtM – Allon Guralnek May 04 '10 at 07:21
  • Five `OR`s 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. – ELLIOTTCABLE May 04 '10 at 08:07
  • 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. – Allon Guralnek May 04 '10 at 17:19

5 Answers5

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

sprhawk
  • 221
  • 3
  • 3
  • Wow, great find! ([Bringing a little more information from their various pages](http://meta.stackexchange.com/a/8259/140656) 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? =) – ELLIOTTCABLE Dec 20 '15 at 17:30
8

https://github.com/DrPizza/libdispatch

DrPizza
  • 17,882
  • 7
  • 41
  • 53
  • Great work and blog posts as well. There has been no updates since a few years ago. Is it still functioning? – kakyo Sep 09 '19 at 06:25
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.

Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93
  • 1
    yes these are the equivalent technologies. http://blogs.msdn.com/nativeconcurrency is the team blog for the Concurrency Runtime and http://blogs.msdn.com/pfxteam is the .NET team blog. – Rick May 02 '10 at 17:28
  • Is this available to C++? – kakyo Sep 09 '19 at 02:13
  • 1
    @kakyo Yes, the Concurrency Runtime is for C++11: https://learn.microsoft.com/en-us/cpp/parallel/concrt/concurrency-runtime?view=vs-2019 – Allon Guralnek Sep 10 '19 at 11:34
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.

Kitsune
  • 9,101
  • 2
  • 25
  • 24
  • 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. – Lothar Nov 15 '15 at 12:32
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.

Gabe
  • 84,912
  • 12
  • 139
  • 238