Board index » cppbuilder » About locking canvas in secondary thread
AlexB
CBuilder Developer |
About locking canvas in secondary thread2007-12-20 03:45:34 PM cppbuilder22 Hi all. There were some posts in QC group about reports Report #: 43018 Status: Closed TBitmap.Draw is unsafe in multithreading apps qc.codegear.com/wc/qcmain.aspx and Report #: 55871 Status: Open TJPEGImage.Draw() is not thread safe qc.codegear.com/wc/qcmain.aspx The #43018 problem: ACanvas.Draw(0, 0, bitmap); is not thread safe (even if ACanvas is locked) and in addition we must lock bitmap: bitmap.Canvas.Lock; try ACanvas.Draw(0, 0, bitmap) finally bitmap.Canvas.Unlock; end; Report is closed ("Test case error", de facto "As designed"). But there is contradiction even from the formal point of view: documentation says only about locking of canvas, but Draw gets TBitmap as parameter. In other words I should do some assumptions about Draw internals and lock bitmap.canvas myself. At present for safety I lock all canvases of all objects in secondary thread when I do any operation (with canvas, scanline, etc) even if I don't touch these objects from other threads. (for example, in thread I do as follows new Bitmap Bitmap->Canvas->Lock ... operation with Bitmap ... Bitmap->Canvas->Unlock delete Bitmap ) Is this redundant ? And if yes - when I exactly must do locking ? TIA. -- Alex |