473,473 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem in deleting the dynamic memory in a parent thread that is allocated from a child thread

Hi,

I am creating a C++ dll which is used to process data passed to it
through one of its exported functions. It should be able to process
160 simultaneous requests. For this reason, I have initiated 10 child
threads from the main thread and maintaining a queue of nodes
containing the data to be processed.

The queue node strucute is as follows:
struct SQueueNode
{
SData *m_pData;
bool m_bInProcess;
char* m_strReturnInfo;
SQueueNode *m_pNextNode;
};

As a node is created and added to queue, one of the free child threads
processes the data. It allocates memory for the char* m_strReturnInfo
of the queue node being processed and puts some info into that and
sets the boolean field (m_bInProcess) of the queue node structure to
false and then waits for more requests.

But when the processed node is deleted from the main thread, the
program crashes at the statement where the dynamic memory allocated
for m_strReturnInfo is deleted.

Can I not delete the dynamic memory in a parent thread that is
allocated from a child thread ?

Thx. in advance.
Manisha
Jul 22 '05 #1
2 1726
> Can I not delete the dynamic memory in a parent thread that is
allocated from a child thread ?


Who knows? Your question has nothing to do with C++ since the C++ standard
is completely silent on the subject of threads.

Try asking again on a windows programming group, for instance
news:comp.os.ms-windows.programmer.win32.

John
Jul 22 '05 #2
A win 32 group is a better place for this query.

I think it is a bad idea to have memory allocation / deallocation
scattered across threads. Can you use a class like
std::basic_string<char> instead of a char*? If you have to use a char*
for some function parameters, you could use the c_str() member
function to access the char* within std::basic_string. This would save
you from memory allocation / deallocation worries.

Cheers,
Andy

vi*************@patni.com (Manisha) wrote in message news:<b3**************************@posting.google. com>...
Hi,

I am creating a C++ dll which is used to process data passed to it
through one of its exported functions. It should be able to process
160 simultaneous requests. For this reason, I have initiated 10 child
threads from the main thread and maintaining a queue of nodes
containing the data to be processed.

The queue node strucute is as follows:
struct SQueueNode
{
SData *m_pData;
bool m_bInProcess;
char* m_strReturnInfo;
SQueueNode *m_pNextNode;
};
As a node is created and added to queue, one of the free child threads
processes the data. It allocates memory for the char* m_strReturnInfo
of the queue node being processed and puts some info into that and
sets the boolean field (m_bInProcess) of the queue node structure to
false and then waits for more requests.

But when the processed node is deleted from the main thread, the
program crashes at the statement where the dynamic memory allocated
for m_strReturnInfo is deleted.

Can I not delete the dynamic memory in a parent thread that is
allocated from a child thread ?

Thx. in advance.
Manisha

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias | last post by:
Hi! I had Apache 2.0.47 and PHP 4.3.0 DEV running successfully on a W2k Server. For some reason, I couldn't get PHP to read XML-Attributes with the DOM XML -functions. So I thought, it would be...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
4
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
7
by: Excluded_Middle | last post by:
Suppose I have a struct typdef struct foo { int age; char *name; }foo; now I made a list of foo using
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
16
by: Abubakar | last post by:
Hi all, My solution consists of 2 projects, 1 is a dll (contains sockets functionality, multithreaded), and the other is a wtl gui project. Both are totally unmanaged. The gui app has a edit...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
2
by: presencia | last post by:
Hi everyone, I have written a small program running fine until a Segmentation fault. Using a debugger I have localized the function the fault happens in. The Signal appears during a call to delete...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.