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

Marco van de Voort marcov at stack.nl
Thu Aug 7 11:28:03 CEST 2008


> Am Mittwoch, 6. August 2008 20:41 schrieb Inoussa OUEDRAOGO:
> 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 ..

I would add nodemgr as parameter to create, but with a default value of nil.
If not NIL then just grab the default nodemanager.

That way, people with multithreading concerns can override, and it is
perfectly backwards compatible. 

There is no good system to do this kind of stuff automatic:
- I might have threads but 
   only read a xml config in the mainthread, no need for locks
- I might have a dozen xml readers somewhere, and they all get an own pool
  of nodes, inflating memory. _IF_ it is multithread.




More information about the fpc-devel mailing list