Tuesday, June 26, 2007

C++ threads in C++09

I noticed a recent post on Herb Sutter's blog about online talks on C++09, which included one talk in particular by Lawrence Crowl. If you're into SMP, multi-threading and synchronization, I suggest you look through that video. While the current C++ standard knows nothing of threads, let alone how to synchronize between them; C++09 will include atomic data types, mechanics to synchronize data updates across threads and a re-evaluated sequence point model. The details of the specification are still in the rough, but the posted video does provide some insight with regard to how, but more importantly why, the various additions are being made.

It appears my ThreadSynch library will be going out of business:) It's nice to see that I was onto something, though, especially with the exception re-throwing across threads.

Wednesday, June 20, 2007

Compiling Boost for x64

Boost 1.34 has arrived. Actually it arrived about a month ago, but having had another round of stressful days, nights and weeks at work, and subsequently a much welcome vacation; I haven't been able to catch up with the world till now. I noticed that they've done some updates to the functor libraries, and I'm keen on benchmarking that against my synchronization library, ThreadSynch. As noted on in the source code -- for those who have taken the time to read that -- I do quite a few function object copies, and I'm curious on how that's affected by this version.

Before I start poking around with benchmarks, and other ThreadSynch updates, I thought I'd share my first impressions on the Boost 1.34 package, installation-wise. It appears that the binary packs made available for Windows are missing a few vital libraries, such as the test execution monitor, so rebuilding from source seems to be the only alternative. While doing that, I also noticed that there are no x64 binaries available, so I built those as well. That part is actually my main point, since the Boost Build docs fail to mention the option you apparently need to throw on to make that work.

Step by step Boost x64 + MSVC2005 build guide:
  1. Get Boost 1.34 source zip, from boost.org or sourceforge.
  2. Get the binary distribution of Boost Jam, also from boost.org or sourceforge.
  3. Launch the VS2005 x64 command environment.
  4. Go to the boost source root folder, and do a
    c:\bjampath\bjam --toolset=msvc address-model=64 --stagedir=stage64 stage
  5. Add the x64 lib path (boost\stage64\lib, if compiled as above) to the x64 library paths in the VS user preferences.
  6. Re-compile!
A few notes:
  • Notice that address-model isn't prefixed with the double dashes; that's intentional! If you prefix it, it will not work.
  • You can add -j%NUMBER_OF_PROCESSORS% to the bjam parameters. This will cause a number of commands to execute in parallel if you've got more cores / CPUs.