#1 Re: GDI+ » Is SynGDIPlus Thread-Safe? » 2014-03-05 07:59:34

It is good to hear that it should work.  Many thanks for this library!

Russ

#2 GDI+ » Is SynGDIPlus Thread-Safe? » 2014-03-02 00:33:18

RussB
Replies: 3

Hello,

I have a Delphi XE app that has a

Gdip := TGDIPlusFull.Create('gdiplus.dll');

in the main UI thread.  I then create several threads that read jpg files using SynGDIPlus and converts them to .bmps.  Here is the thread.execute pseudo-code:

procedure ttcTThumbnailDBThread.Execute;
var
  g: TSynPicture;  //this is declared as a local variable to the thread .execute 
  ams: TMemoryStream;
  Src: TBitmap;
begin
  Ams := TMemoryStream.Create;
  Ams.LoadFromFile("a jpg file");
  g := TSynPicture.Create;
  g.LoadFromStream(Ams);
  Src := g.ToBitmap;
  --do something with the resulting bitmap that is now in SRC 
  G.Free;
  Ams.Free;
  Src.Free;
end;

Is the g.LoadFromStream and g.ToBitmap code thread-safe? Microsoft mentions that you should Synchronize the GDI+ object. 

But, in the case of SynGDIPlus, is the object the 'g: TSynPicture' declaration, or is it the Gdip := TGDIPlusFull.Create('gdiplus.dll') declaration?

I guess I am confused about whether the 'g' or 'Gdip' is the actual GDI+ object.

Anyone have any ideas?  Do I need to synchronize all calls to GDI+?

-------

The only thing I can find on this is from

http://msdn.microsoft.com/en-us/library … ip_threads

Thread Synchronization (from the URL above)
It is possible for more than one thread to have access to a single GDI+ object. However, GDI+ does not provide any automatic synchronization mechanism. So if two threads in your application have a pointer to the same GDI+ object, it is your responsibility to synchronize access to that object.
Some GDI+ methods return ObjectBusy if a thread attempts to call a method while another thread is executing a method on the same object. Do not try to synchronize access to an object based on the ObjectBusy return value. Instead, each time you access a member or call a method of the object, place the call inside a critical section, or use some other standard synchronization technique.

----

Cheers,

Russ

Board footer

Powered by FluxBB