Click here to Skip to main content
15,918,049 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: may i read the same object on network from a file? Pin
merc27-Sep-02 17:45
merc27-Sep-02 17:45 
GeneralMouse Cursor Pin
Thanh Pham27-Sep-02 12:24
Thanh Pham27-Sep-02 12:24 
GeneralRe: Mouse Cursor Pin
RedZenBird27-Sep-02 12:53
RedZenBird27-Sep-02 12:53 
GeneralRe: Mouse Cursor Pin
TyMatthews27-Sep-02 13:42
TyMatthews27-Sep-02 13:42 
GeneralRe: Mouse Cursor Pin
Mike Nordell28-Sep-02 13:52
Mike Nordell28-Sep-02 13:52 
GeneralURLDownload to file (secure) Pin
DarrollWalsh27-Sep-02 11:46
DarrollWalsh27-Sep-02 11:46 
GeneralRe: URLDownload to file (secure) Pin
Axter27-Sep-02 16:26
professionalAxter27-Sep-02 16:26 
GeneralThread Parameter, delete, and ClassDestructor :: MFC Pin
valikac27-Sep-02 11:10
valikac27-Sep-02 11:10 
Hi.

I discovered an interesting bug in an MFC multithreaded program. I found that when you delete a pointer to the worker thread's parameter (declared using new operator), the destructor of the class that is part of the parameter is called.

-----
// This is global.
struct THREADPARAMS
{
ClassA *pCA;
}

// This code is in the primary or main thread.

THREADPARAMS *ptp = new THREADPARAMS;

// Assume that clObject is a member variable and is an instance
// of a ClassA.

ptp->pCA = &clObject;
...

CWinThread *Thread = AfxBeginThread(ThreadFunction, ptp, ...);

// Assume everything works.
// Here is ThreadFunction

UINT ThreadFunction(LPVOID *pParams)
{
THREADPARAMS *ptp = reinterpret_cast<threadparams *="">(pParams);

ClassA *pClassA = ptp->pCA;

// Here is the code that causes the bug.
// I studied Jeff Prosise book on MFC.
// Prosise deleted the new struct inside the worker thread.

delete ptp;
-----

Okay. Lets get to the point. "delete ptp" calls ClassA destructor. I am not sure how to get this working.

My goal is to pass into a worker thread pointers to private data members of the primary thread (main) including primitive data type and ADT. I would like to know is the situation above normal or is there a flaw in my design?

Thanks,
Kuphryn
GeneralRe: Thread Parameter, delete, and ClassDestructor :: MFC Pin
Neville Franks27-Sep-02 11:51
Neville Franks27-Sep-02 11:51 
GeneralRe: Thread Parameter, delete, and ClassDestructor :: MFC Pin
valikac27-Sep-02 12:18
valikac27-Sep-02 12:18 
GeneralRe: Thread Parameter, delete, and ClassDestructor :: MFC Pin
RedZenBird27-Sep-02 12:47
RedZenBird27-Sep-02 12:47 
GeneralRe: Thread Parameter, delete, and ClassDestructor :: MFC Pin
valikac27-Sep-02 14:38
valikac27-Sep-02 14:38 
GeneralVS .Net Book Pin
Anonymous27-Sep-02 10:55
Anonymous27-Sep-02 10:55 
GeneralRe: VS .Net Book Pin
RedZenBird27-Sep-02 13:03
RedZenBird27-Sep-02 13:03 
QuestionCListbox scrollbar with new color? Pin
Anonymous27-Sep-02 10:46
Anonymous27-Sep-02 10:46 
GeneralXP popup menu issues Pin
Paul M Watt27-Sep-02 9:35
mentorPaul M Watt27-Sep-02 9:35 
GeneralMore Info Pin
Paul M Watt27-Sep-02 11:22
mentorPaul M Watt27-Sep-02 11:22 
GeneralRe: XP popup menu issues Pin
RedZenBird27-Sep-02 12:50
RedZenBird27-Sep-02 12:50 
GeneralProblem Found Pin
Paul M Watt27-Sep-02 19:39
mentorPaul M Watt27-Sep-02 19:39 
GeneralLaunching another program Pin
Chun Te, Ewe27-Sep-02 9:29
Chun Te, Ewe27-Sep-02 9:29 
GeneralRe: Launching another program Pin
RedZenBird27-Sep-02 10:53
RedZenBird27-Sep-02 10:53 
QuestionIntegrating Perl? Pin
Chun Te, Ewe27-Sep-02 9:25
Chun Te, Ewe27-Sep-02 9:25 
AnswerRe: Integrating Perl? Pin
Lunchy27-Sep-02 9:49
Lunchy27-Sep-02 9:49 
AnswerRe: Integrating Perl? Pin
Scott H. Settlemier27-Sep-02 10:44
Scott H. Settlemier27-Sep-02 10:44 
GeneralRe: Integrating Perl? Pin
Lunchy30-Sep-02 3:12
Lunchy30-Sep-02 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.