From: Christopher S. <cs...@ma...> - 2009-06-30 14:45:39
|
E.Breeveld wrote: > Dear Blitz-supporters, > > For Blitz++ referenece counting to work in a multi-threaded Visual C++ environment, we have made two small changes to memblock.h. Is there some test case where this broke? The VC++ InterlockedIncrement function guarantees atomicity of the increment, but that should hardly be needed when the increment/decrement is guarded by the BZ_MUTEX. On a related note, I'm not sure that Blitz is guarded enough with the mutexes, especially on deallocation. In blockRemoveReference() [line 371], the block is deleted after checking (refcount == 0) via removeReference(). Unfortunately, the only mutex guard is inside removeReference() itself, so it's possible that: Thread 1 calls blockRemoveReference(), which calls removeReference() and returns, refcount == 0. Then it blocks before the delete. Thread 2 calls addReference() to completion, so refcount == 1. Thread 1 finishes execution, calling the delete. ~MemoryBlock() runs, deallocating data for which there is still a valid reference. If there isn't a problem here after all, my apologies. I just spotted this while looking up context to answer the above |