[cairo-bugs] [Bug 103037] Segmentation fault in _cairo_traps_compositor_glyphs

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Oct 9 19:49:59 UTC 2017


--- Comment #15 from Bill Spitzak <spitzak at gmail.com> ---
+       assert (0 && "incorrect use of _cairo_atomic_init_once API (once !=

I think it would be better for the error message to read "use of
_cairo_atomic_init_once_leave without _cairo_atomic_init_once_enter".

Unless you really see another way for that assert to be triggered.

Also it is an annoying fact of life that on the x86 the fastest way to read an
atomic variable "works" in a very useful way:

  Thread 1:
  // x is a large structure, y is a lock-free atomic
  x = foo;
  atomic_set(y, 1);
  // never set y again

  Thread 2:
  // do not read x here
  while (y != 1) { // non-atomic read!
    // code that does other atomic operations
  assert( x == foo ); // this works

Vast amounts of software assumes this works. The trick is that there is no
synchronization, but an assumption that the only way for y==1 to be true is for
a sync to have happened since the atomic_set.

It does not seem like any version of the atomic operations produce the same
instructions as the non-atomic read in GCC. All of them produce a "sync"
(except "relaxed" but that clearly states the assert could fail).

I am certainly not a mt expert, but I have seen people complain about this with
the atomic operations plenty of times to see if anybody can answer this with
one of these answers:

1. Everybody is wrong and the above code can fail on Intel-style processors.

2. The way you get the above in a form that can be ported to other platforms is
to do "<code>".

3. The overhead of the sync is zero (not impossible, the compiler could
optimize it out by seeing that the test is in a loop).

4. Answer 2 or 3 except it is not true because GCC has a bug.

Probably not a big deal for this bit of Cairo, but this can add up, and there
seem to be some experts here as well as people asking this question, so maybe
somebody here can answer it.

, and also the docs claim that you should use "release" when setting the
variable and mixing modes will screw things up, and this code does not want to
do that as it is reusing code that makes more strict assumptions about the
setting of y.

, the missing assumption is that if the sync has not completed then you will
not see a value of y==1.

. I am guessing that "aquire" is supposed to do this but it is not doing it.

And it does not seem to correspond exactly to any atomic model. Maybe "aquire"
except the aquire semantics only apply if a particular value is read. This code
does rely on the fact that x is only referred to in the if statement to prevent
any out-of-order read of x before y is read.

You are receiving this mail because:
You are the QA Contact for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo-bugs/attachments/20171009/06c123ec/attachment.html>

More information about the cairo-bugs mailing list