Thread safety in TeeTree
Posted: Sat Jun 11, 2005 1:41 am
Hi
I want to populate a tree (ie add nodes) from 2 background threads while at the same time allowing the user to interact with the tree (move nodes in design mode, open and close nodes etc). D5. TeeTree 2.0 (is there a later??)
The background threads call synchronize and I can set it up so that they each call a separate tree updating procedure or I guess I could use a critical section in the main thread so that neither worker (background) thread can update the tree until the other is finished.
Maybe that is sufficient for the issues relating to the tree nodes (GUI issues below), but maybe I would be better off replacing TteeList with TthreadedList (keeping your speed enhancements of course <g>).
OK, can you give me your advice on this aspect?
Now, what about the gui and the canvas and any tree-modifying events that the user might generate through mouse and keyboard clicks (eg delete a node) and simple display-modifying events (like scroll). ??
It seems to me that it would be nice to lock the canvas when worker thread tree-updating events are happening, but I am unsure how to do this
(and I am not sure it would be sufficinet), and I would welcome some advice.
Also, I am unsure of the relationship between the various canvasses (canvi?) and some explanation would be appreciated.
I see that
Teecanvas is just class(Tobject) but contains a
property ReferenceCanvas : Tcanvas
but TcustomTeePanel has a DelphiCanvas.
Also, in your CustomShape.pas you draw direct to Tree.Canvas ..
so the tree must have a canvas (but is that a Tcanvas?)
hmm. How do all these fit together? And what do I lock?
I see at
http://www.teechart.net/support/modules ... icle&sid=6
which is the article on realtime charting you suggest directly fiddling around with critical sections for performance reasons
// When using only a single thread, disable locking:
Chart1.Canvas.ReferenceCanvas.Pen.OwnerCriticalSection := nil;
Series1.LinePen.OwnerCriticalSection := nil;
This seems to suggest that there are already critical sections in place but maybe these are just for low level objects like Pen and Brush.
Thanks, in advance, for your help.
I want to populate a tree (ie add nodes) from 2 background threads while at the same time allowing the user to interact with the tree (move nodes in design mode, open and close nodes etc). D5. TeeTree 2.0 (is there a later??)
The background threads call synchronize and I can set it up so that they each call a separate tree updating procedure or I guess I could use a critical section in the main thread so that neither worker (background) thread can update the tree until the other is finished.
Maybe that is sufficient for the issues relating to the tree nodes (GUI issues below), but maybe I would be better off replacing TteeList with TthreadedList (keeping your speed enhancements of course <g>).
OK, can you give me your advice on this aspect?
Now, what about the gui and the canvas and any tree-modifying events that the user might generate through mouse and keyboard clicks (eg delete a node) and simple display-modifying events (like scroll). ??
It seems to me that it would be nice to lock the canvas when worker thread tree-updating events are happening, but I am unsure how to do this
(and I am not sure it would be sufficinet), and I would welcome some advice.
Also, I am unsure of the relationship between the various canvasses (canvi?) and some explanation would be appreciated.
I see that
Teecanvas is just class(Tobject) but contains a
property ReferenceCanvas : Tcanvas
but TcustomTeePanel has a DelphiCanvas.
Also, in your CustomShape.pas you draw direct to Tree.Canvas ..
so the tree must have a canvas (but is that a Tcanvas?)
hmm. How do all these fit together? And what do I lock?
I see at
http://www.teechart.net/support/modules ... icle&sid=6
which is the article on realtime charting you suggest directly fiddling around with critical sections for performance reasons
// When using only a single thread, disable locking:
Chart1.Canvas.ReferenceCanvas.Pen.OwnerCriticalSection := nil;
Series1.LinePen.OwnerCriticalSection := nil;
This seems to suggest that there are already critical sections in place but maybe these are just for low level objects like Pen and Brush.
Thanks, in advance, for your help.