Feeds:
Posts
Comments

Archive for the ‘C++’ Category

A lot of you have been asking me whether there will be some sort of C++ and Beyond in 2014. Also, over the past few years many of you have also asked me if there will ever be a C&B outside North America. I’m pleased to report that we are doing a ‘European Encore’ event reprising previous C&B material.

Today on the C&B blog, Scott announced that yes, there will be a “C++ and Beyond Road Show” in 2014… in Germany! Note that this is different from previous C&B’s because the purpose is to largely repeat the C&B 2013 program at an event in Europe, in order to make it accessible to people who were not able to fly to North America for previous C&Bs. So think of it as a “C&B Encore” or “C&B Greatest Hits Roadshow Edition.”

From the announcement:

You can think of this event as the C&B Road Show, because the organization is a little different from how we’ve done things in the past:

  • Most of the talks will be updated versions of the presentations we gave at C&B 2013. (See the schedule here.) If you were unable to attend C&B this past December, this is your chance to see what you missed.
  • A group dinner on the first day is included.
  • The schedule is a bit compressed, so some aspects of previous C&Bs are not present. These include group breakfasts and evening discussion sessions.

For this event, we’ve partnered with QA Systems, the same company I’ve worked with since 1999 on technical seminars in Europe. They’ll be handling registration and all other logistical and administrative aspects of the event. Consult their web page for C&B 2014 for all the details of this event.

This will be the only C&B in 2014, so we hope to see you in Stuttgart at the end of September for the first-ever C&B in Europe!

For those of you who have attended C&B before and others who’ve been asking me whether there will be a “regular” C++ and Beyond in North America this year with new material, the answer is not this year; we don’t do a new one every year, and we’re skipping this year. If you are looking for a C++ event in North America with new material, do check out CppCon on September 7-12 in the Seattle area – I am currently planning to create some new talks for CppCon, as well as to repeat some of my C&B talks there. I hear tell that Scott and Andrei might be there too, as well as dozens and dozens of our closest speaker friends.

I’m looking forward to seeing many of you at C&B Europe and CppCon this fall!

Read Full Post »

That was fast!

Read Full Post »

If you’re at Build in San Francisco tomorrow afternoon, I invite you to swing by and spend an hour with us in session 2-661:

Modern C++: What you need to know

by Herb Sutter

Build 2014, Room 2005
2:30-3:30 pm, Thursday April 3, 2014

If you’re new to C++, this talk is aimed directly at you. I was asked to give a “foundational talk” about C++, and I decided that meant I should focus on addressing two questions that I get a lot these days:

  • FAQ #1 (1-2 slides): When should I use C++ compared to another language – on all platforms in general, and on Microsoft platforms in particular?
  • FAQ #2 (lots of slides): What should I know about C++ if I’m a {Java|C#|JavaScript|Python|…} developer?

Even if you’re a seasoned C++ developer, there are some nuggets and data points in the middle of the talk that I think you will find useful in your own work, and I hope that the talk as a whole will be helpful to you in providing a way to explain C++’s value proposition and give (or link to) an answer when someone asks you FAQ #2.

I think it will be recorded, and will post a link here when the recording is available.

I look forward to seeing many of you there tomorrow afternoon.

Read Full Post »

More news about the first annual CppCon that was announced last week:

CppCon 2014 Call for Submissions

CppCon is the annual, week-long face-to-face gathering for the entire C++ community. The conference is organized by the C++ community for the community and so we invite you to present.

Have you learned something interesting about C++, maybe a new technique possible in C++11? Or perhaps you have implemented something cool related to C++, maybe a new C++ library? If so, consider sharing it with other C++ enthusiasts by giving a talk at CppCon 2014. Submissions deadline is May 15 with decisions sent by June 13. For topic ideas, possible formats, and submission instructions, see the Submissions page.

Note that speakers get free registration to attend the whole conference.

I strongly encourage you to present – not “even if” you’ve never presented before, but “especially if” you haven’t. At 5 days x ~5 tracks x ~6 full-length talks per day, this is a big conference with a lot of room for half-length (30 min), full-length (60 min) and multi-hour formal talks (this is in addition to Lightning Talks, which will be arranged later).

For an idea of talks, from the Submissions page:

We are open to any topic that will be of interest to a mainstream C++ audience. Below are some ideas.

  • C++11
  • C++ libraries and frameworks of general interest
  • C++14 and new standardization proposals
  • Parallelism/multi-processing
  • Concepts and generic programming
  • Functional programming
  • High performance computing
  • Software development tools, techniques, and processes for C++
  • Practical experiences using C++ in real-world applications
  • Industry-specific perspectives: mobile and embedded systems, game development, high performance trading, scientific programming, robotics, etc.

I know a number of people who are already planning to submit talks, and I am certain we will get talks on all these topics, and likely more.

As for me, I’m going to go propose a talk on lock-free programming now… everyone should have fun with lock-free mail slots and linked lists, and know when to worry about the ABA problem (and know how to solve it in portable C++11 code).

What should you do next?

If you have a talk idea, run don’t walk to submit a talk – but don’t register for the conference yet as you will get free registration for the conference if your talk is accepted.

Otherwise, register today! The first 100 to register get the Super Early Bird rate of $695 for the whole conference, and registration got off to a strong start since it opened last week – a good number of first-100 places are still available. This is the coolest and most informative event for C++ in nearly 20 years, and whether you’re a C++ novice or an expert you are going to have a great time and learn a lot of practical information and skills you can use on your project today.

Read Full Post »

We have CppCon…

I’m really excited about this event!

Note that the first 100 registrations get a big discount – pasting from the “registration” page:

Regular registration fee is $995 but the first 100 attendees can take advantage of Super Early Bird registration and pay only $695. After that, the Early Bird registration fee is $845 and is valid until the 1st of June. …

The announcement went live four hours ago, and the first registrations have already started to come in.

The full text of today’s announcement follows:

 

CppCon 2014 Registration Open

Opening Keynote by Bjarne Stroustrup
September 7–12, 2014
Bellevue, Washington, USA

Registration is now open for CppCon 2014 to be held September 7–12, 2014 at the Meydenbauer Center in Bellevue, Washington, USA. The conference will start with the keynote by Bjarne Stroustrup titled “Make Simple Tasks Simple!

CppCon is the annual, week-long face-to-face gathering for the entire C++ community. The conference is organized by the C++ community for the community. You will enjoy inspirational talks and a friendly atmosphere designed to help attendees learn from each other, meet interesting people, and generally have a stimulating experience. Taking place this year in the beautiful Seattle neighborhood and including multiple diverse tracks, the conference will appeal to anyone from C++ novices to experts.


What you can expect at CppCon:

  • Invited talks and panels: the CppCon keynote by Bjarne Stroustrup will start off a week full of insight from some of the world’s leading experts in C++. Still have questions? Ask them at one of CppCon’s panels featuring those at the cutting edge of the language.
  • Presentations by the C++ community: What do embedded systems, game development, high frequency trading, and particle accelerators have in common? C++, of course! Expect talks from a broad range of domains experts focused on practical C++ techniques, libraries, and tools.
  • Lightning talks: Get informed at a fast pace during special sessions of short, less formal talks. Never presented at a conference before? This is your chance to share your thoughts on a C++-related topic in an informal setting.
  • Evening events and “unconference” time: Relax, socialize, or start an impromptu coding session.

CppCon’s goal is to encourage the best use of C++ while preserving the diversity of viewpoints and experiences, but other than that it is non-partisan and has no agenda. The conference is a project of the Standard C++ Foundation, a not-for-profit organization whose purpose is to support the C++ software developer community and promote the understanding and use of modern, standard C++ on all compilers and platforms.

Read Full Post »

S&S Postscript

PS on the previous post regarding Stroustrup & Sutter:

I had asked the organizers whether it would be possible to get a piano in the room.

I just learned a few minutes ago that they will be able to arrange a baby grand. Sweet!

This is going to be fun…

Read Full Post »

It has occurred to me that I never announced this event here…

In two weeks, Bjarne and I will be doing a two-day Stroustrup & Sutter on C++ seminar in the San Francisco Bay area. It has been several years since the last S&S event, so Bjarne and I are really looking forward to this.

Super C++ Tutorial: Stroustrup & Sutter on C++

EE Live!
March 31 – April 1, 2014
McEnery Convention Center
San Jose, CA, USA

Registration

The organizers have kindly made sure they can expand the room, so seats are still available. Sorry for the short notice here on this blog.

Using C++ atomics: Lock-Free Algorithms and Data Structures in C++

Here’s one interesting content update: The sessions page lists our talks, including a talk by me with the title “Three Cool Things in C++ Concurrency,” which is pronounced “I hadn’t decided what exactly I wanted to talk about by the time I had to submit the session description.”

I have now decided, and the talk will be entirely on how to design and write lock-free algorithms and data structures using C++ atomic<> – something that can look deceptively simple, but contains very deep topics. (Important note: This is not the same as my “atomic<> Weapons” talk; that talk was about the “what they are and why” of the C++ memory model and atomics, and did not cover how to actually use atomics to implement highly concurrent algorithms and data structures.)

This talk is about the “how to use them successfully” part of atomics, including:

  • Best practices and style for using atomic<>s
  • Three examples, including lock-free mail slots and iterations of a lock-free linked list, all in portable Standard C++
  • Defining and applying the different levels of “lock-freedom” (wait-free, lock-free, obstruction-free) to develop highly concurrent algorithms and data structures
  • Explaining and applying key concepts including especially: linearizability; trading off concurrency vs. promptness; and trading off concurrency vs. throughput/utilization
  • Demonstrating and solving the ABA problem, with clean and simple code – that’s right, did you know that in C++11 you can solve this without relying on esoterica like double-wide CAS (which isn’t always available) or hazard pointers (which are deeply complex) or garbage collection (which isn’t in the C++ standard… yet)?

A few of you may have seen part of this material in the few times I’ve taught the extended four-day version of my Effective Concurrency course. This version of the material is significantly updated for C++11/14 and also contains new material never before seen even if you did take in the four-day EC course – including that instead of leaving the slist example as a cliffhanger, I present an actual complete solution for the slist example that is (a) correct and (b) can be entirely written using portable Standard C++11. It’s always nice to end with a solution you can actually use, instead of just an open problem cliffhanger…

I’m looking forward to seeing many of you in San Jose in two weeks!

Read Full Post »

Quick answer: Yes.

I see there was also a thread about this on StackOverflow, so I’ll echo this Q&A publicly for others’ benefit and hopefully to dispel confusion.

Duncan Forster asked:

I’m quite alarmed the C++ committee chose such a bad interface for std::atomic compare_exchange, i.e.:

    bool compare_exchange_???(T& expected, T desired, …);

I notice you have mentioned (here reader-qa-how-to-write-a-cas-loop-using-stdatomics) that the committee had doubts whether it was a good idea.
Your quote below:

  • Usage note: In the code at top we save an explicit reload from ‘a’ in the loop because compare_exchange helpfully (or “helpfully” – this took me a while to discover and remember) stores the actual value in the ‘expected’ value slot on failure. This actually makes loops simpler, though some of us are still have different feelings on different days about whether this subtlety was a good idea… anyway, it’s in the standard.

The reason I think it’s not only bad but also dangerous is that we now have a race condition baked into the standard. Race condition you say? All hardware CAS implementations that I know of only return 1 value (the old value). Yet the C++ version has 2 returns (success/failure as a boolean return and the old value by reference). So how can an atomic class which is suppose to implement atomic methods do this? Answer is it can’t, the boolean result is calculated after the atomic exchange has occurred. That leaves us with a method which is only partially atomic and with the bonus of a built-in race condition!

Perhaps I haven’t convinced you, so here’s some code to help. I have simulated the hardware CAS with simple C++ code to help demonstrate the problem. The crux of the problem is this statement: while(!atomic_bool_compare_and_swap(&head, new_node->next, new_node))
By creating a 1-line while loop and passing new_node->next as the expected value, if someone is also consuming data the new_node will temporarily be visible by 2 threads. The other thread may process and delete the node before atomic_bool_compare_and_swap has calculated success/failure. This would result in a spurious failure and the new_node actually being pushed twice onto the queue. As you can image this should lead to double delete and possibly the process aborting.

template<typename _T>
bool atomic_bool_compare_and_swap(_T *value, _T& expected, _T new_value)
{
_T old_value;

// Here be atomic
{
old_value = *value;
if(old_value == expected)
*value = new_value;
}

// Here be race conditions
return (old_value == expected);
}

[... more code that exercises this function ...]

 

I don’t believe there is an implementability bug in the standard. Rather, your code is incorrect.

In the above code, presumably only *value is intended to be atomic (and presumably it assumes *value is of a type with a size and alignment that will naturally be written to atomically by the hardware or this code will see torn reads).

General technique: A useful “quick and dirty” analysis of any lock-free code is simply to look at all uses of *value (the atomic thing) as a sanity check. Each use (read, write, or read-modify-write) of the variable is itself atomics, but if there is more than one use you have to view it as a timing window and “mind the gap.”

Based on that quick look here, it seems the comments in the code are backwards:

  • The part labeled “atomic” is not atomic – it accesses *value twice, leaving a timing window where you can lose updates.
  • The part labeled “race conditions” is fine (or would be if the block before it really were atomic) – it is only accessing local variables.

Let’s say you have a CAS that returns only the old value, but doesn’t set “expected,” as you describe below. Then you should just be able to implement the standard one in terms of that – quick sketch (untested code):

    template<typename _T>
bool atomic_compare_exchange(_T *value, _T& expected, _T new_value)
{
_T old_value;

// If all you have is a CAS that returns the old value, use that:
old_value = CAS(value, expected, new_value);

bool result = old_value == expected;
expected = old_value;
return result;
}

 

Notice that there’s only one use of “value” and so no timing window.

If I’m misunderstanding the question, or have a bug in my thinking, please let me know in the comments.

Read Full Post »

I just posted my trip report from last week’s ISO C++ meeting over on isocpp.org. The meeting just wrapped up about 48 hours ago, on Saturday afternoon.

This is a real milestone for C++. Not only did we finish C++14 (we think, assuming this coming ballot comes back clean so that we can skip the final extra ballot step), but we made strong progress on all seven (7) of the Technical Specifications in flight… and approved starting an eighth (8th)!

Good times.

Thanks, everyone who worked so hard to make this happen.

Read Full Post »

GotW #96: Oversharing

Following on from #95, let’s consider reasons and methods to avoid mutable sharing in the first place…

 

Problem

Consider the following code from GotW #95′s solution, where some_obj is a shared variable visible to multiple threads which then synchronize access to it.

// thread 1
{
lock_guard hold(mut_some_obj); // acquire lock
code_that_reads_from( some_obj ); // passes some_obj by const &
}

// thread 2
{
lock_guard hold(mut_some_obj); // acquire lock
code_that_modifies( some_obj ); // passes some_obj by non-const &
}

 

JG Questions

1. Why do mutable shared variables like some_obj make your code:

(a) more complex?

(b) more brittle?

(c) less scalable?

 

Guru Questions

2. Give an example of how the code that uses a mutable shared variable like some_obj can be changed so that the variable is:

(a) not shared.

(b) not mutable.

3. Let’s say we’re in a situation where we can’t apply the techniques from the answers to #2, so that the variable itself must remain shared and apparently mutable. Is there any way that the internal implementation of the variable can make the variable be physically not shared and/or not mutable, so that the calling code can treat it as a logically shared-and-mutable object yet not need to perform external synchronization? If so, explain. If not, why not?

Read Full Post »

Older Posts »

Follow

Get every new post delivered to your Inbox.

Join 1,977 other followers