Board index » cppbuilder » Queue in a thread problem, content no more valid
T. Meyer
![]() CBuilder Developer |
Queue in a thread problem, content no more valid2006-09-14 01:12:32 PM cppbuilder18 Hello, I have a problem using a queue in a thread. I have a thread working with a queue. This queue contains POINTERS to my class TS2IRecord (see my attachments under newsgroup borland.public.attachments from 08.09.06) class TS2IRecord { private: AnsiString A; AnsiString B; AnsiString C; ... } In the function Start (TMyThread.cpp) strange things happen on debugging: I set a breakpoint to the line TS2IRecord *Test0 = RecordWriteFIFO.front(); // In Function Start in TMyThread.cpp Then I execute the program. It stops at the breakpoint above. Then I move the cursor to next line: RecordWriteFIFO.pop(); and press F4 (to execute until cursor) The line *Test0 = RecordWriteFIFO.front(); is executed and the cursor stops at line RecordWriteFIFO.pop(); as expected. Then *Test0 contains garbage. The content ABC, DEF, GHI is not available anymore, it shows only garbage like uninitilaized memory. But if I set the breakpoint directly to RecordWriteFIFO.pop(); and execute MyApp then *Test0 contains "ABC", "DEF", "GHI" like requested. So what is wrong there? I cannot understand! I need this to free the occupied memory by TS2IRecord correctly, but if my pointer just points to garbage, how to free? The thing I want to achieve is: 1. Fill a read FIFO (queue) with pointers to TS2IRecord by creating new instances of TS2IRecord and push their pointers on th read FIFO. 2. Do something with the TS2IRecord instances by accessing them over their pointers 3. If thread is terminated pop all pointers and free the instances What I am doing wrong? Thanks for any help! |