BoostCon 2011 Trip Report

July 3rd, 2011

Here is my belated BoostCon 2011 trip report. As you probably already know, there are slides and, thanks to Marshall Clow, videos for most of the talks (as I am writing this post, only the first half of the videos have been uploaded, but I have it on good authority that the second half will start appearing as early as this week).

If I have to sum it all up in one sentence, it was great. The talks were interesting, the questions and discussions that followed were insightful, and the people were great. I had this feeling of collaboration, of a close-knit bunch of people with a common goal that you don’t get at bigger events. Everyone had a chance to talk to everyone.

The talks ranged from fairly theoretical as in “what can I do in C++ that nobody has ever dreamed of doing before” to very practical, hands-on tutorials. Because there were two parallel tracks, you could usually find something interesting to attend and if not, you could always chat to someone in the lobby. The Boost.Proto library was big at this year’s BoostCon. The running joke at the conference was the compile times of Proto-based examples. The exchange would normally go like this: “How long does it take to compile this example?”, “Oh, it’s less than half an hour. Ok, then you are clearly not using Proto for this”.

Below is a one or two paragraph summary and my impressions of the talks that I have attended. As you will see, most of them gravitate toward the practical side.

Boost Library in a Week

I attended only the first Library in a Week (LIAW) session. Because of the large number of libraries in the review queue, it was decided that instead of creating a new library, the session will try to review one or more existing libraries. Later this was also used to test-drive some of the ideas and tools that were suggested during the Boost Infrastructure Workshop as improvements for the review process .

Thinking Asynchronously: Designing Applications with Boost.Asio

This talk by Christopher Kohlhoff started with an introduction to the ASIO library for asynchronous network and, more generally, IO programming. It then continued by covering more advanced topics such as the best ways of dealing with the inversion and non-continuity of control as well as the state (such as buffers) lifetime management.

To me, the asynchronous approach felt too complicated for a typical program. Yes, there are applications that need to handle hundreds of thousand of connections simultaneously. But for the rest of us, multiple threads with blocking or select/poll-based IO could make things much simpler. In fact, for quite some time now I had an idea of unifying non-blocking IO (select) and synchronization primitives (condition variables) to allow, for example, a thread to wait for a socket to be readable by waiting on a condition variable instead of calling select(). It was interesting to discuss this with Chris and hear his thoughts on the idea.

Native XML Processing Using Multi-paradigm Design in C++

This presentation by Sumant Tambe was about LEESA, a tool that offers an XPath-like EDSL for XML access. It was nice to hear CodeSynthesis XSD, on which LEESA is built, mentioned in the talk as well as the fact that some people in the audience clearly found the data binding interface generated by XSD more natural ;-).

Boost Infrastructure Workshop

This was a very interesting session led by Dave Abrahams. He started the workshop by asking people what they thought was broken or needed improvement when it came to the Boost infrastructure and what areas they would be interested working on. Items that ended up on the blackboard included migration to github, migration to CMake, buildbot, review process, and migration to WordPress for the Boost website.

The review process in particular seemed to be a serious bottleneck which started an interesting exchange of ideas about the possible solutions. I proposed a crazy idea to get away with reviews altogether and Dave confirmed that it was indeed crazy. I also attended a couple of more infrastructure workshops in the following days focusing on finding ways to improve the review process.

Intel’s C++ Software Transactional Memory Compiler

This was an introduction to the software transaction memory (STM) by Justin Gottschlich. STM is another way to support concurrency that is modelled after the database transactions. What baffled many in the audience including myself is what happens when an exception is thrown from within a transaction. In the proposed specification such a transaction would be considered as successfully committed.

The Proposed Boost B-tree Library

In this talk Beman Dawes described his B-tree library which has an interface that is modelled very closely after the standard map and set containers. So essentially you get persistent associative containers with the B-tree representation. What was interesting is the performance of fully-cached B-tree containers compared to their standard counterparts (which are normally implemented as RB-trees). Because a B-tree keeps related nodes close to each other in memory (or on disk) and modern processors employ multiple levels of caching, one can tune a B-tree to outperform RB-tree when it comes to the lookup operations.

Parsing C++ with GCC plugins

I had to attend this talk since I was the speaker and I think it went quite well. I got the impression that after my presentation people had a pretty good idea about what it takes to parse C++ with a GCC Plugin. Fortunately, the comparison to Clang didn’t start a flame war. Luckily for me, Sebastian, who is a Clang contributor, only showed up after I was through with this part. We also had a very nice discussion about possible applications we can write now that we have a complete and mature C++ parser at our disposal.

Threads and Shared Variables in C++0x

This was the keynote by Hans Boehm. The talk went through thread pretty quickly and concentrated mainly on the C++ memory model and atomics. While you can find all this information in the standard or working papers, what was really valuable to me were the questions from the audience and the resulting discussions. I hope you can hear those in the video. We also got a chance to practice this a bit in the lock-free programming talk that followed.

Lockfree Programming Part 2: Data Structures

This was an introduction to lock-free data structures by Tony Van Eerd. Tony used the new atomic support from C++-11 throughout his code so if you are not familiar with this, I suggest that you first watch Hans’ presentation that I mentioned above.

I had no background in lock-free data structure so it was surprising and interesting to discover that there is no, for example, a single lock-free queue implementation. Instead, there is a queue with a single supplier and a single consumer or a queue with a single supplier and multiple consumers. And all of them have quite different implementations. What was less surprising is how hard it is to reason about the correctness of the lock-free implementations. The goal with such data structures is always to impose as little synchronization (in terms of memory fences or similar) as possible. Understanding why a certain synchronization is necessary or not is really hard.

Object-relational mapping with ODB and Boost

Had to attend this talk as well. Overall I think it went very well. There were quite a few questions where people were imagining how they would use ODB in their applications and wanted to clarify some things. I liked that. In particular, support for database schema evolution was a common question so I know what to concentrate on next. Everyone seemed to like the C++-embedded query language and the fact that it is very fast to compile.

Why C++0x is the Awesomest Language for Network Programming

The first part of this talk by Christopher Kohlhoff was the end of his Monday ASIO talk that he had to rush through. When it came to C++0x, the only feature that made a real difference was the rvalue-references. Chris could use them to minimize the amount of allocations and deallocation in ASIO.

Chris also tried to use lambdas, which seemed like a natural fit for asynchronous programming. However, because of the memory management difficulties, stack-less coroutines turned out to be a much better fit. So the last part of the talk was about his implementation of coroutines in C++. Needless to say, the underlying implementation isn’t pretty. For example, from his talk I learned that we can do these kind of things:

int i = 0;
switch (s)
{
  for (; i < 10; ++i)
  {
    case 0:
    ...
  }
  ...
}

BoostCon 2012 Kickoff Meeting

This was a planning meeting for next year’s BoostCon. The big takeaway out of this session was the decision to try and convert BoostCon to a more general C++ conference. It felt like there was a total agreement among the participants that C++ lacks such a conference and that now, with C++0x almost certainly becoming C++11, it would be a great opportunity to do this. I sure hope that it will happen.

Boost.Generic: Concepts without Concepts

In this talk Matt Calabrese showed how he implemented a large portion of the C++ concepts feature which was dropped from the upcoming standard using the C++ preprocessor. The resulting macro-language is quite similar to the original syntax, if a bit ugly. But overall, the amount that Matt managed to achieve given the constraints is impressive. We also got a glimpse at the complexity of the underlying implementation which left me thinking that this code is probably not going to be usable in any real project any time soon (compiler support issues, slow compilation, etc). Maybe some bits and pieces can be used, though.

Boost.Process: Process management in C++

This presentation by Boris Schaeling was essentially a post-mortem on a library that was rejected by a review process. What was surprising to me is that Boris first did a pre-review of this library on the Boost developer list. He then addressed whatever deficiencies were pointed out to him and submitted the library for the “real” review expecting smooth sailing.

Future of Boost Panel

I only managed to attend half of the Future of Boost panel and still catch my plane out of Aspen. But I am sure I stayed for the most interesting part. In a nutshell, Boost now has a formal executive committee which will be responsible for making high-level “policy” decisions. As Dave said, up until now it wasn’t clear who can or should make such decisions. The initial membership consists of the long-time Boost moderators.

Overall, I enjoyed the conference a lot. BoostCon attracts a large number of very smart C++ people and it was fun sharing my ideas and hearing what others are up to. If you are a C++ “go to” guy in your company and you sometimes feel that your colleagues are too slow, come to BoostCon and you will know what it feels like to be on the other side of the equation;-).

See you at BoostCon 2011

May 3rd, 2011

I am giving two talks at this year’s BoostCon conference. The first is titled “Parsing C++ with GCC plugins”. It is about the new GCC plugin architecture and how it can be used for parsing C++.

The second talk is titled “Object-Relational Mapping with ODB and Boost”. It covers the ODB object-relational mapping (ORM) system for C++ and its integration with Boost.

If any of you are attending the conference, please say Hi!

ODB 1.4.0 released

April 27th, 2011

ODB 1.4.0 was released today.

In case you are not familiar with ODB, it is an object-relational mapping (ORM) system for C++. It allows you to persist C++ objects to a relational database without having to deal with tables, columns, or SQL, or manually writing any of the mapping code.

This version includes a number of major new features, small improvements, and bug fixes. For an exhaustive list of changes, see the official ODB 1.4.0 release announcement. As usual, below I am going to examine the most notable new features in more detail.

Qt profile

Two versions ago we announced the Boost profile. Now it is Qt’s turn. As you may remember, ODB profiles are a generic mechanism for integrating ODB with widely-used C++ frameworks and libraries. A profile provides glue code which allows us to seamlessly persist various components, such as smart pointers, containers, and value types found in these frameworks and libraries.

In this initial release the Qt profile covers the most commonly used basic types (QString and QByteArray), date-time types (QDate, QTime, and QDateTime), smart pointers (QSharedPointer and QWeakPointer plus their lazy variants, QLazySharedPointer and QLazyWeakPointer), and containers (QVector, QList, QLinkedList, QSet, QMap, QMultiMap, QHash, and QMultiHash). For example, now we can write:

#pragma db object
class Employee
{
  ...
 
  QString first_name_;
  QString last_name_;
 
  QDate born_;
 
  QSet<QString> emails_;
  QByteArray publicKey_;
 
  QSharedPointer<Employer> employer_;
};

As is evident from the code fragment above, we don’t need to do anything special to use Qt types in our persistent classes. All we need are these three simple steps:

  1. Download and build the Qt profile library, libodb-qt
  2. Specify the Qt profile when invoking the ODB compiler. For example:
    odb -d mysql --profile qt employee.hxx
    
  3. Link the profile library to your application.

And that’s it. That’s all we need to do. For more detailed information on ODB profiles in general, refer to Chapter 13, “Profiles Introduction” in the ODB Manual. For more information on the Qt profile, see Chapter 15, “Qt Profile”.

Inheritance

ODB now supports persistent class inheritance. In this version only non-polymorphic, reuse-style inheritance is supported with each class mapped to a separate database table that contains all the data members, including those inherited from base classes.

It is now also possible to declare a persistent class abstract. Instances of such a class are not stored in the database. Rather, it is used as a base for other persistent classes. For example:

#pragma db object abstract
class person
{
  ...
 
  std::string first_;
  std::string last_;
};
 
#pragma db object
class employee: public person
{
  ...
 
  #pragma db id auto
  unsigned long id_;
};
 
#pragma db object
class contractor: public person
{
  ...
 
  #pragma db id
  std::string email_;
};

For the above example the database schema will contain only two tables, employee and contractor, with the following definitions:

CREATE TABLE employee (
  first TEXT NOT NULL,
  last TEXT NOT NULL,
  id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT);
 
CREATE TABLE contractor (
  first TEXT NOT NULL,
  last TEXT NOT NULL,
  email VARCHAR (255) NOT NULL PRIMARY KEY);

For more details on inheritance, refer to Chapter 8, “Inheritance” in the ODB Manual as well as the inheritance example in the odb-examples package. Support for polymorphic inheritance is coming in future versions of ODB.

C++ enum mapping

ODB can now automatically map C++ enumerations to suitable database types. Let’s say we define C++ type color like this:

enum color {red, green, blue};

If we are targeting the MySQL database, which supports ENUM SQL type, then color will be automatically mapped to ENUM('red', 'green', 'blue'). If the target database does not support enumerations, such as SQLite, then the ODB compiler will map color to a suitable integer type.

It is also easy to override this mapping. Let’s say we always want to store color as an integer, even in databases such as MySQL. Then we can specify the desired type explicitly:

#pragma db value type("INT UNSIGNED")
enum color {red, green, blue};

Or, maybe, our convention is to capitalize the enumerators in the database. We can do that as well:

#pragma db value type("ENUM ('RED', 'GREEN', 'BLUE')")
enum color {red, green, blue};

There are also other important features in this release, including, the new id_type pragma and consistent size_t type mapping. Refer to the official ODB 1.4.0 release announcement for more details on these and other features.