Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-11-29 12:38:22

In message <9036bj+107ri_at_[hidden]>, William Kempf <sirwillard_at_my-> writes
>--- In boost_at_[hidden], Kevlin Henney <kevlin_at_c...> wrote:
>> In message <8vttdv+tjq9_at_e...>, William Kempf <sirwillard_at_my-
>>> writes
>> >> >> Exactly. It would be part and parcel of the function object
>> >> >> requirements.
>> >> >
>> >> >Except that the requirements don't always exist.
>> >>
>> >> I'm not sure what you mean by this: They would exist inasmuch as
>> >> template parameter requirements exist. And if they are not
>> >> that is the problem of the client code rather than the supplied
>> >code.
>> [...]
>> >I believe the argument was being made to internalize thread
>> >synchronization in the callback. I stated that you don't always
>> >a requirement that callbacks be thread safe (they can be used in
>> >single threaded programs, or can be insured to never be passed
>> >thread boundaries). Simply internalizing thread synchronization
>> >would be prohibitive in these cases, since it will add significant
>> >overhead in memory and speed.
>> Aha, I see we are coming from different perspectives: I was taking
>> point of the view that the object must be thread safe whereas you
>> viewing thread safety as equivalent to synchronisation.
>> Whilst synchronisation is one way of ensuring thread safety in the
>> presence of change, my point was that lock-free synchronisation (eg
>> atomic operations) and immutable objects satisfied the requirement.
>> other words, the requirement would be that operator(), or any other
>> would be thread safe, for some appropriate implementation of thread
>> safety for the functional object. Sorry for the confusion, I should
>> been more explicit.
>I did not think you were coming from this angle because frankly, it
>can't be done generically.

Of course it can! It's a non-functional requirement, just as many of the
generic requirements are.

>A lot of function objects must carry
>state around with them, state which is modified with each invocation
>of operator().

Some, but certainly not the major part. Function objects fall into three
categories wrt state:

(1) Stateless, eg functions, many of the function object types in the
standard, many predicates, many transformations.

(2) Stateful but with fixed state, eg many bound function objects, many
of the other function object types in the library, many predicates, many

(3) Stateful but with changeable state, eg RNGs, accumulators.

In my experience, category (1) and (2) cover most of the uses, eg the
callback examples cited, predicates, etc would fall into these
categories, hence no need for synchronisation. Category (3) is the
minority category, IME, and it is only category (3) that definitely
requires synchronisation.

>No, lock-free synchronization doesn't appear to be an option here,
>unless you've got some technique in mind that I've not seen.

Lock-free and no-synchronisation are both options. I'm not sure what you
are not seeing!

However, to counter that, I raised this option only to suggest that it
was too restrictive. If you look at one of my original emails, I
rejected this option and COW because they were unworkable or awkward for
one reason or another, which left proper copying as the appropriate
solution. I suspect this discussion exists for reasons of

>> >I just see major restrictions that shouldn't exist. Why only
>> >nullary, unary and binary? Where's trinary? Quadnary? (sp? on
>> >of those)
>> Ternary and quaternary :-) I suggested nullary, unary and binary
>> they are the only we have support/concepts for in Boost and the
>> standard.
>I doubt this will remain in the future, so to restrict yourself here
>is a mistake.

I am not restricting myself, I am restricted by the library. Given that
the components in the library are open to change (by us), I do not
consider this to be much of an issue: establishing semantics and
interface principles is so far ahead of it that it vanishes in the rear
view mirror :->


  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289

Boost list run by bdawes at, gregod at, cpdaniel at, john at