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

Discussion in 'C++' started by Manisha, Sep 13, 2004.

  1. Manisha

    Manisha Guest

    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
    Manisha, Sep 13, 2004
    #1
    1. Advertising

  2. > 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
    John Harrison, Sep 13, 2004
    #2
    1. Advertising

  3. Manisha

    Andy Guest

    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

    (Manisha) wrote in message news:<>...
    > 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
    Andy, Sep 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    616
    Matt Wharton
    Dec 9, 2004
  2. Rohit
    Replies:
    7
    Views:
    398
    Prawit Chaivong
    Mar 1, 2005
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,111
    David Schwartz
    Dec 9, 2003
  4. Noel Dolan
    Replies:
    0
    Views:
    227
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    130
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page