2

My problem seems to be this: heap data allocated by one thread (that later dies) seems to die as well. As so:

  1. Thread X: starts
  2. Thread Y: starts
  3. Thread X: ptr = new some bytes
  4. Thread X: dies
  5. Thread Y: tries to use ptr - and crashes!

So far, I've only seen this problem on Darwin (Mac OS 10.5 and 10.6), but haven't tried more other platforms than Windows and Linux (Ubuntu) where it works as expected. I've had this problem for some time, so any know-how or more information about this is highly appreciated!

Edit: the problem was caused by an unrelated crash bug.

trincot
  • 317,000
  • 35
  • 244
  • 286
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
  • 1
    C++ makes no mention on how or where memory is allocated. That said, typically different threads share the same heap, so you should be able to pass pointers between them. Perhaps Thread X is freeing the memory before it finishes? – GManNickG Mar 15 '10 at 08:53
  • If Thread X frees memory, it's done implicitly. Is there some way to check/control such behavior? – Jonas Byström Mar 15 '10 at 10:06
  • Not really. If you can't control thread X, you could make a class that outputs something on destruction. Check if X is deleting it that way. – GManNickG Mar 15 '10 at 16:24

1 Answers1

2

Do threads have a distinct heap?
This thread has some good information regarding this subject

Community
  • 1
  • 1
default
  • 11,485
  • 9
  • 66
  • 102