<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Unthread-safe fonts are shared between threads"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=104561">104561</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unthread-safe fonts are shared between threads
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>cairo
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>chris@chris-wilson.co.uk
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jmuizelaar@mozilla.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>cairo-bugs@cairographics.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Running pthread-show-text with the following patch shows that all threads are
sharing the same cairo_font_face_t. However cairo_font_face_t are not thread
safe.

diff --git a/test/pthread-show-text.c b/test/pthread-show-text.c
index 0f076cb61..4069fd756 100644
--- a/test/pthread-show-text.c
+++ b/test/pthread-show-text.c
@@ -67,6 +67,7 @@ draw_thread (void *arg)
                            CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size (cr, NUM_ITERATIONS);
+    printf("font: %p\n", cairo_get_font_face(cr));
     cairo_font_extents (cr, &extents);

     cairo_move_to (cr, 1, HEIGHT - extents.descent - 1);


Additionally running with thread sanitizer gives:
TESTING pthread-show-text
pthread-show-text.image.rgb24 [0x1]:    font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
font: 0x7b1400002850
==================
WARNING: ThreadSanitizer: data race (pid=356)
  Write of size 4 at 0x7b54000114b8 by thread T3 (mutexes: write M109):
    #0 _cairo_scaled_font_freeze_cache
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:796:31
(libcairo.so.2+0x12b597)
    #1 INT_cairo_scaled_font_text_to_glyphs
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:2034:5
(libcairo.so.2+0x12ea6c)
    #2 cairo_show_text /home/jrmuizel/src/cairo/src/cairo.c:3552:14
(libcairo.so.2+0x193244)
    #3 draw_thread /home/jrmuizel/src/cairo/test/pthread-show-text.c:85:2
(cairo-test-suite+0x54e428)

  Previous read of size 4 at 0x7b54000114b8 by thread T8:
    #0 INT_cairo_scaled_font_destroy
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:1326:5
(libcairo.so.2+0x129cdd)
    #1 _cairo_gstate_unset_scaled_font
/home/jrmuizel/src/cairo/src/cairo-gstate.c:1709:2 (libcairo.so.2+0x6a144)
    #2 _cairo_gstate_set_font_size
/home/jrmuizel/src/cairo/src/cairo-gstate.c:1719:5 (libcairo.so.2+0x6efa7)
    #3 _cairo_default_context_set_font_size
/home/jrmuizel/src/cairo/src/cairo-default-context.c:1224:12
(libcairo.so.2+0x5ce8f)
    #4 INT_cairo_set_font_size /home/jrmuizel/src/cairo/src/cairo.c:3164:14
(libcairo.so.2+0x1922c0)
    #5 draw_thread /home/jrmuizel/src/cairo/test/pthread-show-text.c:81:2
(cairo-test-suite+0x54e3aa)

  Location is heap block of size 536 at 0x7b5400011300 allocated by thread T1:
    #0 malloc <null> (cairo-test-suite+0x431d7b)
    #1 _cairo_ft_font_face_scaled_font_create
/home/jrmuizel/src/cairo/src/cairo-ft-font.c:2016:19 (libcairo.so.2+0x24b48f)
    #2 INT_cairo_scaled_font_create
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:1144:14
(libcairo.so.2+0x12d19b)
    #3 _cairo_gstate_ensure_scaled_font
/home/jrmuizel/src/cairo/src/cairo-gstate.c:1915:19 (libcairo.so.2+0x6f5ca)
    #4 _cairo_gstate_get_scaled_font
/home/jrmuizel/src/cairo/src/cairo-gstate.c:1787:14 (libcairo.so.2+0x6f3c4)
    #5 _cairo_default_context_get_scaled_font
/home/jrmuizel/src/cairo/src/cairo-default-context.c:1300:14
(libcairo.so.2+0x5d31f)
    #6 INT_cairo_get_scaled_font /home/jrmuizel/src/cairo/src/cairo.c:3348:12
(libcairo.so.2+0x192823)
    #7 cairo_show_text /home/jrmuizel/src/cairo/src/cairo.c:3529:19
(libcairo.so.2+0x193003)
    #8 draw_thread /home/jrmuizel/src/cairo/test/pthread-show-text.c:85:2
(cairo-test-suite+0x54e428)

  Mutex M109 (0x7b5400011478) created at:
    #0 pthread_mutex_lock <null> (cairo-test-suite+0x438fa5)
    #1 _cairo_scaled_font_freeze_cache
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:795:5 (libcairo.so.2+0x12b57a)
    #2 INT_cairo_scaled_font_text_to_glyphs
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:2034:5
(libcairo.so.2+0x12ea6c)
    #3 cairo_show_text /home/jrmuizel/src/cairo/src/cairo.c:3552:14
(libcairo.so.2+0x193244)
    #4 draw_thread /home/jrmuizel/src/cairo/test/pthread-show-text.c:85:2
(cairo-test-suite+0x54e428)

  Thread T3 (tid=361, running) created by main thread at:
    #0 pthread_create <null> (cairo-test-suite+0x4326f6)
    #1 draw /home/jrmuizel/src/cairo/test/pthread-show-text.c:107:13
(cairo-test-suite+0x54e06a)
    #2 cairo_test_for_target /home/jrmuizel/src/cairo/test/cairo-test.c:933:14
(cairo-test-suite+0x4c6dd4)
    #3 _cairo_test_context_run_for_target
/home/jrmuizel/src/cairo/test/cairo-test.c:1536:15 (cairo-test-suite+0x4c45c0)
    #4 _cairo_test_runner_draw
/home/jrmuizel/src/cairo/test/cairo-test-runner.c:247:12
(cairo-test-suite+0x4cceb4)
    #5 main /home/jrmuizel/src/cairo/test/cairo-test-runner.c:937:13
(cairo-test-suite+0x4ca5e8)

  Thread T8 (tid=366, running) created by main thread at:
    #0 pthread_create <null> (cairo-test-suite+0x4326f6)
    #1 draw /home/jrmuizel/src/cairo/test/pthread-show-text.c:107:13
(cairo-test-suite+0x54e06a)
    #2 cairo_test_for_target /home/jrmuizel/src/cairo/test/cairo-test.c:933:14
(cairo-test-suite+0x4c6dd4)
    #3 _cairo_test_context_run_for_target
/home/jrmuizel/src/cairo/test/cairo-test.c:1536:15 (cairo-test-suite+0x4c45c0)
    #4 _cairo_test_runner_draw
/home/jrmuizel/src/cairo/test/cairo-test-runner.c:247:12
(cairo-test-suite+0x4cceb4)
    #5 main /home/jrmuizel/src/cairo/test/cairo-test-runner.c:937:13
(cairo-test-suite+0x4ca5e8)

  Thread T1 (tid=358, running) created by main thread at:
    #0 pthread_create <null> (cairo-test-suite+0x4326f6)
    #1 draw /home/jrmuizel/src/cairo/test/pthread-show-text.c:107:13
(cairo-test-suite+0x54e06a)
    #2 cairo_test_for_target /home/jrmuizel/src/cairo/test/cairo-test.c:933:14
(cairo-test-suite+0x4c6dd4)
    #3 _cairo_test_context_run_for_target
/home/jrmuizel/src/cairo/test/cairo-test.c:1536:15 (cairo-test-suite+0x4c45c0)
    #4 _cairo_test_runner_draw
/home/jrmuizel/src/cairo/test/cairo-test-runner.c:247:12
(cairo-test-suite+0x4cceb4)
    #5 main /home/jrmuizel/src/cairo/test/cairo-test-runner.c:937:13
(cairo-test-suite+0x4ca5e8)

SUMMARY: ThreadSanitizer: data race
/home/jrmuizel/src/cairo/src/cairo-scaled-font.c:796:31 in
_cairo_scaled_font_freeze_cache
==================
pthread-show-text.image.rgb24 [0x1]:    FAIL
ThreadSanitizer: reported 1 warnings
pthread-show-text: UNTESTED</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>