Bug 104561 - Unthread-safe fonts are shared between threads
Summary: Unthread-safe fonts are shared between threads
Status: RESOLVED MOVED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Chris Wilson
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-09 19:14 UTC by Jeff Muizelaar
Modified: 2018-08-25 13:55 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jeff Muizelaar 2018-01-09 19:14:56 UTC
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
Comment 1 GitLab Migration User 2018-08-25 13:55:39 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/269.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.