[cairo] Cairo and multithreading einvironment.
ranma42 at gmail.com
Thu Jul 21 23:28:01 PDT 2011
On Fri, Jul 22, 2011 at 2:48 AM, cu <cairouser at yahoo.com> wrote:
> Cairo seems to be getting "less" thread-safe as time goes on. We are
> using version 1.9.8 which we found to be most multithreading-friendly.
> We still have to serialize all text operations and of course no two
> threads can render to the same surface at the time. However, 1.9.8
> permits simultaneous rendering into separate surfaces and even allows
> the same source to be used for more than one surface at a time.
> Unfortunately every version after 1.9.8 was non-thread safe for all of
> the above operations - so we can't upgrade (probably ever, since there
> does not seem to be much effort in this direction).
The test suite checks the behavior of multithreaded drawing in pthread-*
The problem you describe should be solved in cairo master by
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sat Feb 19 17:46:45 2011 +0200
image: Avoid reusing pixman images for threadsafety.
The pixman_image_ref() and pixman_image_unref() functions
aren't threadsafe in current pixman, so we can't share
pixman images across contexts where they may end up
moving between threads. The main use of these functions
is in keeping a global cache of pixman_image_ts for
solid colours and reusing the same pixman_image_t for
patterns pointing to the same image data where possible.
This patch removes those uses from cairo by wrapping
them in a PIXMAN_HAS_ATOMIC_OPS conditional. There is
no automatic test this, so we will have to manually
turn this code back on when pixman does gain atomic
The only two remaining calls to pixman_image_ref() are
done on locally created images so they are safe.
There is ongoing work into improving both the thread safety of
cairo and pixman and their multithreaded performance.
PS: please report bugs (if possible with self-contained code to
reproduce the problem) for any remaining issues related to
multithreading. (I know of a couple of issues with multithreading
& snapshots, but afaict most of cairo should now be threadsafe)
> Horodyski Marek (PZUZ) wrote:
>> > -----Original Message-----
>> > From: Horodyski Marek (PZUZ)
>> > Sent: Friday, July 15, 2011 12:28 PM
>> > To: cairo at cairographics.org
>> > Subject: Cairo and multithreading einvironment.
>> > Cairo works well in an sigle thread environment, but I have problems in
>> > multi-threaded.
>> When I use Cairo In MultiThread environment without mutex synchronize,
>> on monitor I see :
>> cid:image002.png at 01CC1723.7C2D4EA0
>> I can work with mutex synchronize, but but it costs time L
>> Example code :
>> hSurface := cairo_pdf_surface_create( "TEST.PDF", 566.9, 793.7 ) //
>> 200x280 mm in pt
>> hCairo := cairo_create( hSurface )
>> cairo_set_source_rgb( hCairo, 0, 0, 0 )
>> cairo_select_font_face( hCairo, "verdana", CAIRO_FONT_SLANT_NORMAL, 0 )
>> cairo_set_font_size( hCairo, 6 )
>> cairo_move_to( hCairo, 1, 7 )
>> cairo_show_text( hCairo, "Some text")
>> cairo_show_page( hCairo )
>> cairo_destroy( hCairo )
>> cairo_surface_destroy( hSurface )
>> String "TEST.PDF" in different thread are differ.
>> Marek Horodyski
>> cairo mailing list
>> cairo at cairographics.org
> cairo mailing list
> cairo at cairographics.org
More information about the cairo