Concurrency Town Hall: On the web, this Monday, December 3

Earlier this fall, James Reinders and I each gave concurrency webcast as part of Intel’s fall webcast series. On Monday, James and I are going to be following that up with a virtual Town Hall panel discussion on concurrency, with Dr. Dobb’s editor Jon Erickson as our moderator. Should be cool. And you are invited to attend.

Here are the coordinates:

Date: Monday, December 3, 2007

Time: 9:00-10:00am U.S. Pacific Time

Registration: http://www.life20.net/intel1reg.php

Web simulcast (doesn’t require Second Life): http://www.slcn.tv

I expect that most people will be watching the event via the live simulcast on Second Life Cable Network. Use that if you’re not a Second Life member, or if you are a member but can’t get in there because the SL servers are expected to reach their maximum capacity for a single event.

There’s also a network breakfast before the town hall portion. Here’s the full description, as it appears on Intel’s site:

SOFTWARE AND THE CONCURRENCY REVOLUTION: DESIGNING FOR MULTIPLE CORES

A virtual Town Hall held in Second Life by Intel Software Network and Dr. Dobb’s Journal

December 3, 2007 8:00 AM – 11:00 AM Pacific Time (11:00 AM – 1:00 PM ET) on Intel and Dr Dobb’s Islands.

Meet Intel and Industry experts, learn about parallel programming and concurrency trends, let your voice be heard.

This half day event will begin with a networking breakfast on Dr. Dobbs Island where you will have the ability to meet some of Intel’s best engineers. Tim Mattson (Intel Principal Engineer, Designer of the 80 Core test chip parallel application and one of the creator’s of Open MP*) will give a brief introduction on our transition to a many-core world.

Following breakfast, attendees will adjourn to Intel Island for the virtual town hall. This event will be moderated by Jonathan Erickson (Editorial Director, Dr. Dobb’s) and will feature Herb Sutter (Architect, Microsoft, and chair of the ISO C++ Standards committee) and James Reinders (Chief Evangelist and Threading Guru for Intel Software Products) who will debate and discuss issues involved in realizing the promise of parallelization. As in any town Hall, your input will be vital.

After the town Hall, Peretz Stine of Intel Island and Rissa Maidstone of Dr. Dobbs will lead tours of their respective islands.

Schedule for December 3, 2007:
• 8:00-9:00 AM SLT – Networking Breakfast with Tim Mattson
• 9:00-10:00 AM SLT – Town Hall Meeting with Jon Erickson, James Reinders and Herb Sutter
• 10:00-11:00 AM SLT – Tour of Intel and Dr. Dobbs Islands

You must register to reserve a place at this event: http://www.life20.net/intel1reg.php
This event will be simulcast live on Second Life Cable Network: http://www.slcn.tv

Visual C++ Announcements in Barcelona: TR1 and MFC

Note: Many of you who read this blog aren’t Windows developers. I think you might still be interested in skimming this announcement, because I think it matters to the cross-platform and global C++ community when major vendors are clearly still investing heavily in C++ and C++-based technologies, despite what some naysayers proclaim.

How much does Microsoft care about C++ and non-.NET code? In August, I already blogged about

Now I’m happy to elaborate beyond just hinting, in the wake of announcements made yesterday by our Developer Division VP Soma and by our Visual C++ team. Here’s the scoop.

This month: Visual Studio 2008 ("Orcas") ships

First the comparatively minor news: We have a ship date. By the end of this month, we will ship Visual Studio 2008 ("Orcas"), including Visual C++ 2008 in particular which includes a number of cool features I’ve blogged about before, such as /MP for parallel builds on multicore machines.

But VC++ isn’t stopping there. Instead of waiting another year or two between releases, we’re immediately doing another one, gratis to VC++ 2008 customers:

First half of 2008: VS2008 Update ships

In the first half of 2008, VC++ is additionally going to ship an "expansion pack"-like update that will be available to all owners of Visual Studio 2008 Standard and above. This includes two major pieces that I know will be welcome in two major developer communities.

TR1

"TR1" is the first set of library extensions published by the C++ committee, nearly all of which have also been adopted into the next C++ standard, C++0x. Now that we know what parts seem to be sealed for inclusion in the next C++ standard and stable, we can start shipping them.

The VC++ 2008 update will include a complete implementation of all parts of TR1 that were voted into C++0x, except only for the section on functions added for compatibility with the C99 standard. The update will include features like:

  • smart pointers (e.g., shared_ptr<T>, weak_ptr<T>)
  • regular expression parsing
  • new containers (e.g., tuple, the fixed-size array<T,N>, hash-based containers like unordered_set<T>)
  • sophisticated random number generators
  • polymorphic function wrappers (e.g., function<bool(int)> and bind)
  • type traits

and a bunch more of all that good stuff lurking inside ISO C++ Library TR1. C++0x may tweak some of the interfaces, and we’ll track that as they do. In the meantime, here they are right in VC++.

A huge update to MFC

I hinted about a "huge update to MFC" back in August. Here’s the scoop…

Using this update to MFC, developers will be able to create applications with the “look and feel” of Microsoft’s own UIs:

  • Vista theme support, allowing your application to dynamically switch between themes.
  • The Office 2007 UI, including the Ribbon bar look in all its glory, with the ribbon itself, the pearl, quick access toolbar, status bar, and more.
  • The Office 2003 and XP UI, including Outlook-style shortcut bar, Office-style toolbars and menus, print preview, live font picker, color picker, etc.
  • The Internet Explorer UI, including rebars and task panes in all their glory.
  • The Visual Studio UI, with sophisticated docking functionality, auto hide windows, property grids, MDI tabs, tab groups, and more.

All in native C++ code. In MFC.

Oh, and there are also more things… for example, you can also enable your users to customize your application "on the fly" through live drag and drop of menu items and toolbar buttons; use the new Windows shell management classes to enumerate folders, drives and items, browse for folders, and more; and take advantage of many more new controls you can use right out of the box.

Want a quick tour? Get your quick overview with lots of screen shots in our own Pat Brenner’s VCblog entry, and also check out this handy Channel 9 video interview with Pat.

Implementation notes

Where did we get the code? This time, we decided to buy rather than build. The code for Office 2007 look-and-feel and other items were based on code we got from BCGSoft rather than code we developed internally.

Some people wondered about this, but it’s just an implementation detail. In particular, here are two questions I’ve seen people ask, and my personal answers (I am not speaking for Microsoft):

Q: Does it matter that this is code originally written by another company (BCGSoft)?

A: No. This update is a Microsoft Visual Studio product, full stop. With the full level of testing and support that implies, today and tomorrow.

Like most software companies, Microsoft routinely both builds its own code and integrates licensed software. We’ve long done the latter for the C++ standard library implementation (from Dinkumware), the Office proofing tools and spelling/grammar/thesaurus/hyphenation/etc. dictionaries, and mapping data for Live, to name just a few off the top.

Q: Does it matter that this isn’t the code the Office team used to implement their own look-and-feel? Why didn’t Microsoft ship Office’s own internal code?

A: No, and because we usually don’t because internal code isn’t at the level required of a product, respectively. I wonder if people realize this is the norm, not the exception, so let me explain a little.

Think of Office as the biggest Windows ISV (independent software vendor) that operates mostly as a separate company, even though it happens to be a sister division. Office has always driven the development of their own UI advances separately from Windows and Visual Studio. Windows and Visual Studio, in turn, have always tried to follow quickly in adding support for Office’s advances so that the Windows shell and other third-party applications could present the same look-and-feel wherever they wanted to, and those implementations have usually been:

  1. Later, because Office drove the innovation and the platform and tools followed.
  2. Different from Office’s own internal home-brewed versions, because there’s a huge difference between "solid for internal use" and "productized" with all the additional level of documentation and testing and external usability that requires.

The fact that we have an internal and an external "real" implementation for the same thing doesn’t matter. We’ve always done it that way, and the "real" implementation is equal and fully supported. (I think it’s funny that some worry that they’re not getting Office’s original internal ‘real’ implementation; the real "real" implementation is the one that’s not just for internal use, almost by definition!) Once a UI innovation gets into the Windows UI and/or especially the Visual Studio toolset, it’s first-class and here to stay.

Finally, I said this a huge update. What does "huge" mean? This update nearly doubles the size of MFC. Now, "nearly do
ubles the size of X" can be a bad thing. In this case, though, it’s a Good Thing… in my opinion, at least.

Beta and release availability

The update is expected to be available in beta form in January 2008, and to ship in the first half of 2008. Enjoy!

Wrapping up

Finally, let me express some well-deserved appreciation for a HUGE amount of hard work invested by the Visual C++ team, and our libraries team in particular, to make this happen and bring it to customers. Those of us who spend a good fraction of our lives on the second floor of Building 41 saw it firsthand, and know how hard everyone on the team has worked to make this happen at high quality. Thanks for that; it’s been quite a year of PM design work, coding and QA milestones, bug bars, and shiprooms.

For those who’ve asked what Visual C++ is planning beyond this month’s release, the above is an additional part of the answer. Far from the last part, however, because as Ale Contenti said in his announcement on VCblog about our plans beyond VC++ 2008:

"This is just the first step in our drive to improve the native development experience.  There’s a lot more that we’re working on, but we hope you enjoy this first milestone."

Stay tuned.

Effective Concurrency: Avoid Calling Unknown Code While Inside a Critical Section

The latest Effective Concurrency column, "Avoid Calling Unknown Code While Inside a Critical Section", just went live on DDJ’s site, and will also appear in the print magazine. Here’s a teaser from the article’s intro:

Don’t walk blindly into a deadly embrace…

Our world is built on modular, composable software. We routinely expect that we don’t need to know about the internal implementation details of a library or plug-in to be able to use it correctly.

The problem is that locks, and most other kinds of synchronization we use today, are not modular or composable. That is, given two separately authored modules, each of which is provably correct but uses a lock or similar synchronization internally, we generally can’t combine them and know that the result is still correct and will not deadlock. There are only two ways to combine such a pair of lock-using modules safely: …

I hope you enjoy it.
Finally, here are links to previous Effective Concurrency columns (based on the dates they hit the web, not the magazine print issue dates):
July 2007 The Pillars of Concurrency
August 2007 How Much Scalability Do You Have or Need?
September 2007 Use Critical Sections (Preferably Locks) to Eliminate Races
October 2007 Apply Critical Sections Consistently

Trip Report: October 2007 ISO C++ Standards Meeting

The ISO C++ committee met in Kona on October 1-6. Here’s a quick summary of what we did, and information about upcoming meetings.

What’s in C++0x, and When?

As I’ve blogged before (most recently here and here), the ISO C++ committee is working on the first major revision to the C++ standard, informally called C++0x, which will include a number of welcome changes and enhancements to the language itself as well as to the standard library.

The committee is determined to finish technical work on this standard in 2009. To that end, we plan to publish a feature-complete draft in September 2008, and then spend the next year fine-tuning it to address public feedback and editorial changes.

Note that this represents essentially a one-year slip from the schedule I blogged about at the beginning of the year. Why the slip? There are a few major features that haven’t yet been "checked in" to the working paper and that are long poles for this release. Here are three notable ones:

  • concepts (a way to write constraints for templates that lets us get way better error messages, overloading, and general template usability)
  • advanced concurrency libraries (e.g., thread pools and reader-writer locks)
  • garbage collection

Probably the biggest thing we did at this meeting was to choose time over scope: We decided that we can’t ship C++0x without concepts, but we can and will ship without some or all of the other two.

Concurrency: This was a pivotal meeting for concurrency. We voted a slew of concurrency extensions into the working draft at this meeting, as they happily all got to the ready point at the same time (see below for details):

  • memory model
  • atomics library
  • basic threads, locks, and condition variables

And we decided to essentially stop there; we still plan to add an asynchronous future<T> type in C++0x, but features like thread pools are being deferred until after this standard.

Garbage collection: For C++0x, we’re not going to add explicit support for garbage collection, and only intend to find ways to remove blocking issues like pointer hiding that make it difficult to add garbage collection in a C++ implementation. In particular, the scope of this feature is expected to be constrained as follows:

  • C++0x will include making some uses of disguised pointers undefined, and providing a small set of functions to exempt specific objects from this restriction and to designate pointer-free regions of memory (where these functions would have trivial implementations in a non-collected conforming implementation).
  • C++0x will not include explicit syntax or functions for garbage collection or related features such as finalization. These could well be considered again after C++0x ships.

What we voted into draft C++0x

Here is a list of the main features we voted into the C++0x working draft at this meeting, with links to the relevant papers to read for more information.

nullptr (N2431)

This is an extension from C++/CLI that allows explicitly writing nullptr to designate a null pointer, instead of using the unfortunately-overloaded literal 0 (including its macro spelling of NULL) which makes it hard to distinguish between an null and a zero integer. The proposal was written by myself and Bjarne.

Explicit conversion operators (N2437 and N2434)

You know how in C++ you can make converting constructors only fire when invoked explicitly?

class C {
public:
  C( int );
explicit C( string );
};

void f( C );

f( 1 ); // ok, implicit conversion from int to C
f( "xyzzy" ); // error, no implicit from string literal to C
f( C("xyzzy") ); // ok, explicit conversion to C

But C++ has two ways to write an implicit conversion — using a one-argument constructor as above to convert "from" some other type, or as a conversion operator "to" some other type as shown below, and we now allow explicit also on this second form:

class C {
public:
  operator int();
explicit operator string(); // <– the new feature
};

void f( int );
void g( string );

C c;
f( c ); // ok, implicit conversion from C to int
g( c ); // error, no implicit from C to string
g( string(c) ); // ok, explicit conversion to C

Now the feature is symmetric, which is cool. See paper N2434 for how this feature is being used within the C++ standard library itself.

Concurrency memory model (N2429)

As I wrote in "The Free Lunch Is Over", chip designers and compiler writers "are under so much pressure to deliver ever-faster CPUs that they’ll risk changing the meaning of your program, and possibly break it, in order to make it run faster." This only gets worse in the presence of multiple cores and processors.

A memory model is probably of the lowest-level treaty between programmers and would-be optimizers, and fundamental for any higher-level concurrency work. Quoting from my memory model paper: "A memory model describes (a) how memory reads and writes may be executed by a processor relative to their program order, and (b) how writes by one processor may become visible to other processors. Both aspects affect the valid optimizations that can be performed by compilers, physical processors, and caches, and therefore a key role of the memory model is to define the tradeoff between programmability (stronger guarantees for programmers) and performance (greater flexibility for reordering program memory operations)."

Atomic types (N2427)

Closely related to the memory model is the feature of atomic types that are safe to use concurrently without locks. In C++0x, they will be spelled "atomic<T>". Here’s a sample of how to use them for correct (yes, correct!) Double-Checked Locking in the implementation of a singleton Widget:

atomic<Widget*> Widget::pInstance = 0;

Widget* Widget::Instance() {
  if( pInstance == 0 ) { // 1: first check
    lock<mutex> hold( mutW ); // 2: acquire lock (crit sec enter)
    if( pInstance == 0 ) { // 3: second check
      pInstance = new Widget(); // 4: create and assign
    }
  } // 5: release lock
  return pInstance; // 6: return pointer
}

Threading library (N2447)

You might have noticed that the above example used a lock<mutex>. Those are now in the draft standard too. C++0x now includes support for threads, various flavors of mutexes and locks, and condition variables, along with s
ome other useful concurrency helpers like an efficient and portable std::call_once.

Some other approved features

  • N2170 "Universal Character Names in Literals"
  • N2442 "Raw and Unicode String Literals; Unified Proposal (Rev. 2)"
  • N2439 "Extending move semantics to *this (revised wording)"
  • N2071 "Iostream manipulators for convenient extraction and insertion of struct tm objects"
  • N2401 "Code Conversion Facets for the Standard C++ Library"
  • N2440 "Abandoning a Process"
  • N2436 "Small Allocator Fix-ups"
  • N2408 "Simple Numeric Access Revision 2"

Next Meetings

Here are the next meetings of the ISO C++ standards committee, with links to meeting information where available.

  • February 24 – March 1, 2008: Bellevue, Washington, USA (N2465)
  • June 8-14, 2008: Sophia Antipolis, France
  • September 14-20, 2008: San Francisco Bay area, California, USA (this is the anticipated date)

The meetings are public, and if you’re in the area please feel free to drop by.