Delphi4 string handling finally catches up with me.
From: Martin Harvey (Demon account) (martin_at_nospam_pergolesi.demon.co.uk)
Date: 12/17/04
- Next message: Martin Harvey (Demon account): "Re: Delphi version control"
- Previous message: Jeremy Collins: "Re: Delphi version control"
- Next in thread: Rob Kennedy: "Re: Delphi4 string handling finally catches up with me."
- Reply: Rob Kennedy: "Re: Delphi4 string handling finally catches up with me."
- Reply: Marco van de Voort: "Re: Delphi4 string handling finally catches up with me."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 17 Dec 2004 18:48:16 GMT
Hey folks,
Beautifully obscure bug here, and I have a fix that I *think* will
work, but just want to check.
Multithreaded app - normally at least 6 or 7 threads running at any
time.
Never seen an error on my machine. Run it on a 4xCPU (2x xeon
hyperthreaded box) at work, and it works ... for about a day, and then
dies horribly - one of the threads raises an exception and quits.
Looked into it with the meager debug information I had with me: it
ends up dying in SysAllocMem. All the hallmarks of heap corruption.
Now the one thing I'm *sure* of is that my memory allocation is OK -
In the debug build, I actually log *every* memory allocation in a big
AVL tree that I can then use to check for leaks, and also display an
estimate of memory fragmentation.
So, after eliminating all other causes I can think of, this looks very
much like Delphi 4 string handling. Typically, strings aren't shared,
except in cases where "file descriptors" are passed between one thread
and another. These happen to contain a string: a relative pathname.
So anyways, I now have a scheme to avoid this based on "UniqueString".
Basically, resources always get passed from one thread to another via
a buffer (actually a queue). My plan is that at the point where a
resource is passed into the buffer by the thread that originally
created the string, then I call "UniqueString" so ensure that there
are no references shared across threads.
Sounds OK?
Note that it's probably a BAD idea to call UniqueString when taking
strings out of buffers, because the original "putting in" thread will
have definitely left the critical section, and is probably in an
indeterminate state.
MH.
- Next message: Martin Harvey (Demon account): "Re: Delphi version control"
- Previous message: Jeremy Collins: "Re: Delphi version control"
- Next in thread: Rob Kennedy: "Re: Delphi4 string handling finally catches up with me."
- Reply: Rob Kennedy: "Re: Delphi4 string handling finally catches up with me."
- Reply: Marco van de Voort: "Re: Delphi4 string handling finally catches up with me."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|