DDS-PSM-Cxx 1.0b2 FTF Avatar
  1. OMG Issue

DDSPSMC — Portable exception-safety guarantees for DDS C++ PSM

  • Key: DDSPSMC-10
  • Legacy Issue Number: 16401
  • Status: closed  
  • Source: Real-Time Innovations ( Sumant Tambe)
  • Summary:

    The users of the DDS C++ PSM can benefit significantly if the specification standardizes exception-safety guarantees of the API. Exception safety specification for normative classes would support portable safety guarantees irrespective of vendor implementation and extensions. This would facilitate frictionless transition from one vendor to another in user code.

    Exception safety is about how programs, libraries behave when an exceptional condition arises. It is often much more than just raising an exception. For instance, constructor or copy-ctor of std::string may run out of memory resulting into std::bad_alloc exception. However, in practice, APIs must specify guarantees about the internal state of the data structures after any exception propagates out. Exception-safety guarantees for C++ abstractions come in four categories: strong, basic, nothrow, and neutral. For instance, the push_back member function of std::vector, std::list guarantees that the container remains unchanged (strong exception safety) in case of any exception. In general, programmers expect strong exception safety guarantees but it is often expensive to do so.

    RTI is proposing refined specifications for normative DDS C++ PSM API to make it easier to use even in the face of exceptions.

    1. Strong guarantees for value types:

    All the constructors and copy-assignment operators of normative classes that inherit from Value<D> and the Value<D> template itself should provide strong guarantees. A simple way to achieve that is to ensure that Value<D> template provides strong guarantees and then implement the derived classes in terms of value<D>.

    Not all value types are POD. Some of them use std::string and may throw. Consider, for instance, SubscriptionBuiltinTopicData. Value<D> delegates the assignment to its delegate, SubscriptionBuiltinTopicDataImpl. This impl class has non-pod members such as std::string and does not define its own assignment operator. Assignment of one string (topic_name) may succeed but the assignment of second string (type_name) may fail with a bad_alloc exception. This may result into inconsistent left-hand-side SubscriptionBuiltinTopicData object when DataWriter:: matched_subscription_data is called.

    In general, classes that have more than one non-pod types should have an assignment operator that is strongly safe. Instead of handpicking such classes, Value<D should be made strong exception-safe so that irrespective of vendor-specific extensions, types that users will deal with the most, will be safe to use.

    Proposed solution: Implement the copy-assignment operator of Value<D> using copy-and-swap technique.

    2. At least basic guarantees for reference types:

    Not all implementations may be able to provide strong guarantees for reference types such as DataWriter<Foo>, DataReader<Foo>. Therefore, constructors and copy-assignment operators must provide at least basic guarantees. While Reference<D> itself should provide strong guarantees; just that is insufficient to extend the guarantees to all its derived classes. The normative reference types should provide strong guarantees whenever it is not prohibitively expensive to do so.

  • Reported: DDS-PSM-Cxx 1.0b1 — Fri, 29 Jul 2011 04:00 GMT
  • Disposition: Resolved — DDS-PSM-Cxx 1.0b2
  • Disposition Summary:

    Section 7.3 on page 16 of the specification lists not the mandatory exception safety requiremenst on Value types and Reference Types. Specifically, for reference types it is required that loan-based read/take are exception safe.

  • Updated: Fri, 6 Mar 2015 20:58 GMT