[Mono-winforms-list] Is System.Drawing (libgdiplus) thread-safe?

Alex Shulgin alexander.shulgin at yessoftware.com
Thu Oct 29 11:01:07 EDT 2009


Sebastien Pouliot wrote:
> 
> Please open a bug report on bugzilla.novell.com and attach your test
> case.

https://bugzilla.novell.com/show_bug.cgi?id=551009

>> On my Linux box it crashes all the time.  I get a wide variety of errors 
>> from gdb stacktraces with SIGSEGV or SIGABRT in the end, to SIGILL with 
>> .Net stack trace.
>>
>> Uncommenting these lock {} lines in the ThreadProc helps, but not an 
>> option for my real app, as there's simply no single place a lock could 
>> be added.
>>
>> I've also tried writing some code in plain C which links to libgdiplus 
>> directly: see `threads-gdiplus.c'.  It happily crashes just like the C# 
>> version.
> 
> Most of System.Drawing is only a small wrapper abound libgdiplus (or GDI
> + under Windows). Any bug will likely be inside libgdiplus so it's
> "normal" (i.e. expected) that you get the same behavior.

Yes, it's what I expected.  Just thought it might be helpful in 
debugging the problem.  Attached this to the bug too.

>> My tests show that even using unsynchronized GdipGetImageGraphicsContext 
>> / GdipDeleteGraphics (no fonts stuff touched) can easily lead to crashes.
>>
>>  From what I've seen, cairo seems to be thread-safe: see attached[1] 
>> `cairo-multi-thread-text.c'.
> 
> It's thread-safe as long as everything is created and executed in the
> same thread. Otherwise it would not be safe-thread (just like .net and
> most libraries are).

This is actually what I meant by thread-safe here. :)

I'd expect any library not to crash under similar circumstances as long 
as it doesn't use global variables or, if so, does ensure proper locking 
around them.

--
Regards,
Alex



More information about the Mono-winforms-list mailing list