Re: Memory Allocation in a Multi-Threaded Environment
- From: "Jeff" <someone@xxxxxxxxxxxxx>
- Date: Sun, 8 Jun 2008 18:20:16 +0100
"David Lowndes" <DavidL@xxxxxxxxxxxxxxx> wrote in message
news:dnkn44l5vhk751e51pb8t39nu7tmirq0do@xxxxxxxxxx
I quickly realised that multi-threading opens up a whole new slew of bugs
for the novice, but there is one area that is really confusing me.
I have a small class that uses an std::vector array. I create a new worker
process with afxbeginthread - this process will expand/contract the vector
(and do some other stuff) and then return. The problem is, I seem to get
heap corruption errors when I try to access the memory allocated in the
worker thread after that thread has finised. Is this to be expected or
should I be looking elswhere for the bug?
Jeff,
It's not expected, but without more details it's nigh on impossible to
know where your error lies. Try the same code in a single threaded
test and see if you suffer the same issue.
Thanks a lot for that, I guess the issue must be somewhere else then.
The particular example concerns reading and processing data from a URL file.
A worker thread is created to read the entire file into a buffer whilst the
main thread begins processing the data as it becomes available. The program
was working fine on my local host where the file was "downloaded" almost
before the processing had begun. When I try it on a remote file however the
heap corruption problem arises - I suspect because the processing is now
catching up with the download. I'm using a local data member to synchronise
reading and resizing of the buffer. In particular the buffer can only be
resized if it isn't being read and can only be read if it isn't being
resized - since a resize could move the buffer. I assume that the buffer can
be read and written to simultaneously.
If I do the download before (and in the same thread as) the processing then
I have no problem even with a remote Url.
Does anyone have a pointer to a simple program that does this type of
simultaneous buffer and process operation?
Thanks again
Jeff
.
- Follow-Ups:
- Re: Memory Allocation in a Multi-Threaded Environment
- From: Joseph M . Newcomer
- Re: Memory Allocation in a Multi-Threaded Environment
- From: David Lowndes
- Re: Memory Allocation in a Multi-Threaded Environment
- References:
- Memory Allocation in a Multi-Threaded Environment
- From: Jeff
- Re: Memory Allocation in a Multi-Threaded Environment
- From: David Lowndes
- Memory Allocation in a Multi-Threaded Environment
- Prev by Date: Re: Resource-only DLLs
- Next by Date: Re: Hooking Joystick Messages?
- Previous by thread: Re: Memory Allocation in a Multi-Threaded Environment
- Next by thread: Re: Memory Allocation in a Multi-Threaded Environment
- Index(es):
Relevant Pages
|
Loading