views:

350

answers:

5

We're developing something for the Windows platform and we'd like to harness the multiple cores present in PCs nowadays.

I know that in VS2010, there is the Concurrency Runtime. It's still on Beta, though. For the meantime that we do need to release quality code now, what is a good option for an API that will allow smooth transition later. Other suggestions?

+1  A: 

Intel's Thread Building Block library has a parallel task system that is similar (at a high level) to the Concurrency Runtime. API details will differ, but the work you do to break your program into small tasks that run independently will carry over.

Jesse Hall
You can find out more about the Thread Building Block library at http://www.threadingbuildingblocks.org/ Note that it is a C++ library, so if you are wanting to use it from C code, you will probably have to go with pthreads or OpenMP
garethm
+1  A: 

I have always liked pthreads. It maps pretty well onto the other threading models I've run into, and I've found it relatively easy to program(as compared to, say, MPI).

However, it's not as high-level as the Concurrency Runtime.

I've also heard some noise about OpenMP, but havn't looked into it.

Paul Nathan
You can find out more about pthreads for Windows at http://sourceware.org/pthreads-win32/
garethm
+2  A: 

I suggest using OpenMP while waiting. It is implemented for most compilers, relatively easy to add to existing code, and to use later on with other APIs.

stephan
+2  A: 

I know of:

  • Intel Thread Building Block library (open source)
  • C++0x thread library support (cross platform sometime in the future)
  • Just Software implementation of the C++0x thread library - allows you to have a head start on using the new c++ thread library in vs 2008.
  • OpenMP - build into most C++ compilers these days, including VS 2008.
  • pthreads for win32 - POSIX threads so they are cross platform for any POSIX complaint OS.
  • WIN32 threading API

I would recommend the Intel Thread Building Blocks as it's a higher level of abstraction over most of the other multi-threaded API's. It's also open source so you can download and see how some of the stuff is done. Upcomming versions are meant to use the windows Concurrency Runtime if it's available. I've also read that Intel have submitted TBB to be included into the C++ standard.

pthreads and the Win32 API are lower level primitives that require you to understand the multi-threaded environment a lot better. If you know what you are doing, these tools give you the most control.

I have yet to use the new c++ threading support but they look to be on the same level or a little higher as pthreads. Just Software has some interesting articles on how to use the new c++ thread library.

I have only read about OpenMP and I'm not sure what it's like to use.

You may like to read Joe Duffy's Concurrent Programming on Windows book.

Herb Sutter also posts lots of articles under the title Effective Concurrency.

Hope that helps.

Shane Powell
+1  A: 

Short answer: hire a programmer with good threading experience.

Working with multi threads on multi cores is hard. There is no substitute for experience.

Visual C++ (any recent version) has the tools for developing parallel software, but there are complexities such as data synchronisation that make it very tricky for the inexperienced. The Concurrency Runtime stuff is an attempt to hide the complexity and let the compiler do the work. It may work very well, but the jury is still out. For now, you can get good results with the existing tools, but you need the expertise.

Consider hiring a good contractor to help get the architecture right and train your own staff up to speed.

Michael J
Hi! I'm very sorry for giving the wrong impression that it's our first time doing multi-threading. my question was more on what API/arch to use for "future-proofing". We ARE the that contractor.
moogs
In that case, my response is that there is no "future-proof" solution yet. The VS10 stuff may become one, but not until it is mature. The risks of using it as a beta would be pretty large. The next C++ standard will have some parallel stuff, but it will be still a bit low-level. I'd say use _beginthread() or CreateThread(). Use Critical Sections, Mutexes, Semaphores and Events. It is still a lot of heavy lifting, but at least you are not sweating somebody else's bugs. A good API will come, but it is probably two years from being viable.
Michael J