kov_serg Messages: 42 Registered: August 2008 Location: Russia
Member
I have serious problem with Upp memory allocation in multithreads. This problem dissapear if I don't use UPP_HEAP.
If I allocate, reallocate and free memory in different thread, I have strange bugs. If I force Defs.h "flagUSEMALLOC" problem doesn't occure. I think this is some kind of bug with heap monitor.
The simples example to reproduce this bug attached in file test.cpp (with option MT)
If I call th0(1) programm works fine.
But if argument th0(2) or more it will stop debugger in various places with out visible reason.
In real programm it cause unhandled exception when gui terminates or even fail on vector<>.clear inside GUI thread o_0.
hz1.png -- dubugger stop in unknown place without visible reason. (test.cpp)
hz2.png -- screen shot from other program when this problem occure. (real project) I have exceptions from delete operator. Usually from vector<>.clear(). Exception may occure on different delete operators. And behaviour is very unstable.
BTW, using beginthreadx has a problem with UPP_HEAP -> there is per-thread heap cache that needs to be freed at the and of thread, which is not possible to implement automagically with beginthreadx.
Use Thread class instead. (Or, if you insist, call MemoryFreeThread at the end of thread).
kov_serg Messages: 42 Registered: August 2008 Location: Russia
Member
Here is printf and Sleep only for simplicity. In real code there is no printf at all. Just operations with array mutex and events. And if UPP_HEAP disabled program working stable. This is indeed overloaded new and delete operators comes into play. In case then MemoryFreeThread called before thread end it works fine, but without it it begins falling into a parts after second thread creation.