Multithreaded font rendering on Windows crashes Cairo
Hi guys, I recently got back into developing with Cairo. Around 10 years ago there were problems with font rendering on Windows with Cairo, namely in multithreaded circumstances, since a global Windows device context was involved, if I remember correctly. I thought these had been fixed some time ago, but in my recent tests, I stumbled upon a problem that seems similar:
Example: I have two threads, and in both I run a loop where I create a Cairo surface, draw a text to it (using the toy function) and destroy the context/surface again. This works for a single thread, but fails with either an access violation in Pixman or an assert failure for scaled_font->cache_frozen when running with 2 or more threads, even though the threads only use local data.
Here is a minimal C++ example, tested with Visual Studio 2012 and static builds of Cairo and Pixman from sources. cairotest.cpp
The only solution I have found is to wrap the whole thread loop in a global mutex, but that kind of defeats the multithreaded approach then, although interestingly the problem then no longer occurs. Let me know if you have any ideas or my test is wrong or if I should provide more information.