[cairo] Win32 thread-safety
sgoericke at vandalay.org
Sat Oct 17 12:44:05 PDT 2009
i use cairo (or better: cairomm) for a X-Plane aircraft addon, meaning
it's used in a DLL/.so/.dylib. For text i use(d) the simple "toy-text"
API because it do a good job for my needs. The plugin run fine on Linux
(i use mainly Linux for development and daily use) and also runs fine on
MacOS. Linux-Distribution is Archlinux, OSX Version is still 10.5.8. But
on Windows i come into trouble: using MinGW/GDB i got error messages
from the Microsoft MSVC Runtime-Library "this application has called a
runtime function in a unusual way" or similar. However, GDB keeps the
app running, couldn't tll me what's going wrong with the app bevor i
click "Ok" on the error message-box. Thereafter gdb told me there was a
"std::bad_alloc" exception but couldn't tell me were. So i checked every
"new" etc. in my code, also add a lot "try-catch" statements around them
but nothing helps.
To get closer to the problem i decided to compile and debug the stuff
with MSVC (Visual Studio 2008). I found out the "bad_alloc" exception
was thrown by the cairomm-library (CAIRO_STATUS_NO_MEMORY). But i still
didn't have an idea why. Because the errors are "random" ones it was
hard to find the problem. The first hint i got was that the exception
always was thrown if i did anything with text (get_text_extents(),
show_text() mainly). A hour ago i just found that one of my
drawing-threads has thrown the exception and another called
"cairo_show_text()" the same time. So i came to the conclusion that
there *must* be a probelm with text-handling on Win32 systems. Btw., at
the moment i run up to 8 threads that use cairo and growing.
So i tried a "simple" approach and add a global Mutex to my plugin and
cover every text-related stuff in my code by this Mutex. And surprise
surprise, this helps. But also reduces Performance a bit in the
Application, saying X-Plane.
I also don't longer use "normal" Win32-Font objects and
"set_font_size()" but switched to Win32ScaledFont (which didn't solve
So, my question: is cairomm thread-safe on Win32? I mean the Font/Text
stuff ? Second: if so, is it only thread-safe with native Win32 Threads?
I use pthreads2 for Win32 (i'm happy with that).
used cairo-version: 1.8.8
used cairomm-version: 1.8.2
tested OS: Windows Vista 64bit, Windows 7 64bit, Linux 32bit (Kernel
2.6.30 with PAE and Highmem = 64GB, i have 8GB of RAM, Glibc 2.10),
Anyway, thanks for that highly protable vector-graphics library :-)
More information about the cairo