Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Problem with UPP_HEAP and multithread
Problem with UPP_HEAP and multithread [message #23304] Thu, 08 October 2009 10:58 Go to next message
kov_serg is currently offline  kov_serg
Messages: 37
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.

Upp version: SVN.643
  • Attachment: test.cpp
    (Size: 0.87KB, Downloaded 253 times)
  • Attachment: hz1.PNG
    (Size: 68.32KB, Downloaded 258 times)
  • Attachment: hz2.PNG
    (Size: 48.24KB, Downloaded 291 times)
Re: Problem with UPP_HEAP and multithread [message #23305 is a reply to message #23304] Thu, 08 October 2009 11:00 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Sorry wrong tesp.cpp
  • Attachment: test1.cpp
    (Size: 1.17KB, Downloaded 251 times)
Re: Problem with UPP_HEAP and multithread [message #23306 is a reply to message #23305] Thu, 08 October 2009 11:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Please, compiler version...

And you DO have MT flag in main config, rigth?

Mirek
Re: Problem with UPP_HEAP and multithread [message #23307 is a reply to message #23304] Thu, 08 October 2009 11:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kov_serg wrote on Thu, 08 October 2009 04:58

Upp version: SVN.643


Ehm, could you try something more recent? Smile

Mirek
Re: Problem with UPP_HEAP and multithread [message #23308 is a reply to message #23307] Thu, 08 October 2009 11:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tried with MSC9 and MSC71, no crash Sad

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).
Re: Problem with UPP_HEAP and multithread [message #23309 is a reply to message #23304] Thu, 08 October 2009 12:02 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
OS: WindowsXP SP3 32bit
Compiler: Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

I release 1607 the situation is the same.
??? In designer ancors don't work any more while resize. Why?
They work in SVN.643

Thanks luzr.
But MemoryFreeThread not defined in all versions of build
Re: Problem with UPP_HEAP and multithread [message #23310 is a reply to message #23304] Thu, 08 October 2009 12:06 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
With MemoryFreeThread works perfect. Thanks!
Re: Problem with UPP_HEAP and multithread [message #23311 is a reply to message #23309] Thu, 08 October 2009 12:25 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
kov_serg wrote on Thu, 08 October 2009 11:02


??? In designer ancors don't work any more while resize. Why?
They work in SVN.643


There's a new button up at the top (next the grid and red 'ignore min size' buttons) that disables springs.
Re: Problem with UPP_HEAP and multithread [message #23312 is a reply to message #23310] Thu, 08 October 2009 12:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kov_serg wrote on Thu, 08 October 2009 06:06

With MemoryFreeThread works perfect. Thanks!


That is quite weird and very likely just accidental.

Omitting MemoryFreeThread just avoids ugly silent memory leak, but should not affect the stability.

-> I recommend more testing.

Mirek
Re: Problem with UPP_HEAP and multithread [message #23313 is a reply to message #23312] Thu, 08 October 2009 12:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
BTW, are you 100% sure that printf is reentrant/MT safe?

Maybe you can try just to add mutex for printf...

Mirek
Re: Problem with UPP_HEAP and multithread [message #23333 is a reply to message #23313] Sun, 11 October 2009 10:31 Go to previous message
kov_serg is currently offline  kov_serg
Messages: 37
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.
Previous Topic: starting console app hidden
Next Topic: Splitting a string by a string?
Goto Forum:
  


Current Time: Fri Apr 26 22:27:33 CEST 2024

Total time taken to generate the page: 0.02757 seconds