[fpc-devel] TAVLTree(avl_tree.pp) thread safety, fcl-xml(DOM) is also concerned.

Burkhard Carstens fpc at bcsoft.de
Thu Aug 7 11:35:08 CEST 2008


Am Donnerstag, 7. August 2008 11:15 schrieb Burkhard Carstens:
[...]
>
> What about this:
> * let TAVLTree access the node manager using a local reference
>   (TAVLTree.FNodeMemManager)
> * in TAVLTree.create:
>   if IsMultiThread then
>     FNodeMemManager:=TAVLTreeNodeMemManager.create
>   else
>     FNodeMemManager:=NodeMemManager;
> * in TAVLTree.destroy:
>   if IsMultiThread then
>     FNodeMemManager.free;
>
> This way, nothing would change for single threaded apps but it would
> be fully threadsafe for multithreaded (AFAIKS). This is probably not
> a perfect solution, but the least intrusive one ..

This would have been too easy :-)

IsMultiThread is false until the first thread is started, so we can't 
use that. However, we could use a global var in avl_tree interface like
"var ThreadSafeAVLTree : boolean = false;" instead. This way, we don't 
have it threadsafe automatically, but if needed, the developer can set 
this to true before instantiating the first AVLTree. This is still more 
than we have now without breaking anything existing ..
A big "Note: if you want to use it in multithreaded app, please set 
ThreadSafeAVLTree:=true; before creating the first instance" in the 
docs of AVLTree and XML would be helpfull of course.

regards
  Burkhard




More information about the fpc-devel mailing list