[cairo] Is cairo thread-safe

快乐2013 350137278 at qq.com
Wed May 8 00:55:22 PDT 2013


Hi, I want to use cairo in multi-threads context, anybody know if cairo is thread-safe? especially the cairo_t object.
I found some mutex related code, so i guess cairo lib might be threadsafe.
Who can tell me the truth?

void threadDrawFunc(void *cr)
{
  // do we need lock cr here?
  // lock();

  // sample drawing code
  cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  cairo_set_font_size (cr, 32.0);
  cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
  cairo_move_to (cr, 10.0, 50.0);

  cairo_show_text (cr, text);

  // unlock();
}

void mainThread()
{
         cairo_surface_t *surface =             cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);          cairo_t *cr =             cairo_create (surface);

         create_thread(threadDrawFunc, cr);

         // wait threads to exit
         join_thread(...);

         cairo_destroy (cr);

         cairo_surface_write_to_png (surface, "c:/temp/hello-cairo.png");
         cairo_surface_destroy (surface);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130508/b03a37ca/attachment.html>


More information about the cairo mailing list