Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #158546 > unrolled thread

New sequencing model

Started byAndrey Tarasevich <andreytarasevich@hotmail.com>
First post2021-01-22 01:12 -0800
Last post2021-01-23 08:48 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c


Contents

  New sequencing model Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-01-22 01:12 -0800
    Re: New sequencing model Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-23 08:48 -0800

#158546 — New sequencing model

FromAndrey Tarasevich <andreytarasevich@hotmail.com>
Date2021-01-22 01:12 -0800
SubjectNew sequencing model
Message-ID<rue4tv$f2f$1@dont-email.me>
Hello

As you know, C11 (together with C++11) adopted the new sequencing model 
based in the *sequenced before* relation between evaluations. One 
immediately noticeable property of this sequencing model is that it may 
apply separately to

1. value computations of an evaluation, and
2. side effects of an evaluation

This means that in general case we can sequence value computations and 
side effects independently. The C standard also retains the classic 
notion of *sequence point*, which is now derivative from the above

5.1.2.3
3. [...] The presence of a sequence point between the evaluation of 
expressions A and B implies that every value computation and side effect 
associated with A is sequenced before every value computation and side 
effect associated with B.

This implies that separation between 1 and 2 above in the new sequencing 
model supposedly makes it more flexible than the old model based on 
sequence points. E.g. not every sequencing in C11 is a sequence point.

But where is the tangible benefit of that? Can someone come up with an 
example of where this extra flexibility makes a difference in the language?

Is there an example of, say, an expression whose sequencing becomes more 
free/flexible in the new sequencing model? I.e. an example of an 
expression whose C11 sequencing cannot be equivalently expressed in 
terms of classic C99-style "sequence points"?

I know that the new sequencing model was also (or, perhaps, primarily) 
introduced to support multithreading in C11. So, we'll probably be able 
to find abundant examples of how the above model is critically necessary 
in multithreaded evaluations.

But just out of curiosity I still wonder: is there a "classic" 
*single-threaded* example of something the new sequencing model can 
express, which the old sequencing model could not express equivalently?

-- 
Best regards,
Andrey Tarasevich

[toc] | [next] | [standalone]


#158576

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2021-01-23 08:48 -0800
Message-ID<86v9bnmwf5.fsf@linuxsc.com>
In reply to#158546
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> Hello
>
> As you know, C11 (together with C++11) adopted the new sequencing
> model based in the *sequenced before* relation between
> evaluations.  One immediately noticeable property of this sequencing
> model is that it may apply separately to
>
> 1. value computations of an evaluation, and
> 2. side effects of an evaluation
>
> This means that in general case we can sequence value computations and
> side effects independently.  The C standard also retains the classic
> notion of *sequence point*, which is now derivative from the above
>
> 5.1.2.3
> 3.  [...] The presence of a sequence point between the evaluation of
> expressions A and B implies that every value computation and side
> effect associated with A is sequenced before every value computation
> and side effect associated with B.
>
> This implies that separation between 1 and 2 above in the new
> sequencing model supposedly makes it more flexible than the old model
> based on sequence points.  E.g. not every sequencing in C11 is a
> sequence point.
>
> But where is the tangible benefit of that?  Can someone come up with an
> example of where this extra flexibility makes a difference in the
> language?  [...]

A formalism for sequencing is pretty much necessary to talk about
the semantics of multiple threads.  Since C11 decided to add
threading, it basically had to put in a better sequencing model.

Leaving aside anything having to do with threads or concurrency
(that is, explicit concurrency), my understanding is that the
sequencing rules in C11 are just a more formal and precise way of
saying what had been intended for sequencing relationships in C
all along.  The C standard committee had wanted to do this for a
long time, and several attempts were made even before C99 was
finished.  But those early efforts were deemed unsatisfactory
for whatever reason (and in hindsight rightly so - the C11 model
is definitely better IMO than the earlier efforts).

All this is a rather long way of saying I think the C11 sequencing
rules should be thought of as applying to pre-C11 standards as
well, and not to spend too much time thinking about how the rules
have changed.  AFAICT the intention is that they have not.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web