Click here to Skip to main content
15,910,083 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPrinting Active Documents Pin
Martyn Pearson16-Apr-03 5:29
Martyn Pearson16-Apr-03 5:29 
GeneralMulti-threaded graphics in MFC Pin
Iceman16-Apr-03 5:26
Iceman16-Apr-03 5:26 
GeneralRe: Multi-threaded graphics in MFC Pin
Chris Losinger16-Apr-03 5:47
professionalChris Losinger16-Apr-03 5:47 
GeneralRe: Multi-threaded graphics in MFC Pin
Iceman16-Apr-03 6:07
Iceman16-Apr-03 6:07 
GeneralUse of class function in thread Pin
Tomaz Rotovnik16-Apr-03 5:02
Tomaz Rotovnik16-Apr-03 5:02 
GeneralRe: Use of class function in thread Pin
valikac16-Apr-03 5:35
valikac16-Apr-03 5:35 
GeneralRe: Use of class function in thread Pin
Tomaz Rotovnik16-Apr-03 5:55
Tomaz Rotovnik16-Apr-03 5:55 
GeneralRe: Use of class function in thread Pin
Joaquín M López Muñoz16-Apr-03 8:35
Joaquín M López Muñoz16-Apr-03 8:35 
You have to declare a structure and pass a pointer to it. There are some common problems regarding who owns this structure. Consider the following:
void foo()
{
  data d;
  // fill d;
  CreateThread(...,&d,...)
}
This seems OK and will probably work some times until it suddenly stops to do it. The reason is that, when the thread starts executing and access d, it is perfectly normal that foo has already exited, and d is no longer valid. So, you have to dynamically allocate the data:
void foo()
{
  data* d=new data;
  // fill d;
  CreateThread(...,d,...)
}
Now the problem is who deletes d? The most reasonable choice is to let the thread delete the data:
MyThread(LPVOID arg)
{
  data * d=(data *)arg;
  ...
  delete d; // d no longer needed.
  ...
}
This is almost perfect: you should take into account the rare case when the thread does not launch (due to insufficient resources, for instance):
void foo()
{
  data* d=new data;
  // fill d;
  if(!CreateThread(...,d,...)){
    delete d; // no thread launched, clean up the mess ourselves
  }
}
That's it, hope it helps.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: Use of class function in thread Pin
jason9916-Apr-03 12:53
jason9916-Apr-03 12:53 
GeneralRe: Use of class function in thread Pin
Tomaz Rotovnik16-Apr-03 23:24
Tomaz Rotovnik16-Apr-03 23:24 
GeneralCRichEditView drag and drop.. Pin
RobJones16-Apr-03 4:34
RobJones16-Apr-03 4:34 
GeneralRe: CRichEditView drag and drop.. Pin
G. Steudtel17-Apr-03 4:23
G. Steudtel17-Apr-03 4:23 
GeneralCD-ROM Status Pin
pmask16-Apr-03 3:41
pmask16-Apr-03 3:41 
GeneralRe: CD-ROM Status Pin
David Crow16-Apr-03 4:11
David Crow16-Apr-03 4:11 
GeneralRe: CD-ROM Status Pin
Joaquín M López Muñoz16-Apr-03 4:20
Joaquín M López Muñoz16-Apr-03 4:20 
QuestionHow to make an installer package Pin
gumber16-Apr-03 2:35
gumber16-Apr-03 2:35 
AnswerRe: How to make an installer package Pin
Jim Crafton16-Apr-03 3:15
Jim Crafton16-Apr-03 3:15 
AnswerRe: How to make an installer package Pin
Chris Richardson16-Apr-03 6:34
Chris Richardson16-Apr-03 6:34 
AnswerRe: How to make an installer package Pin
Ravi Bhavnani16-Apr-03 6:36
professionalRavi Bhavnani16-Apr-03 6:36 
GeneralRe: How to make an installer package Pin
Martin_Viet16-Apr-03 8:26
Martin_Viet16-Apr-03 8:26 
GeneralTermination of a thread Pin
Vassili16-Apr-03 2:11
Vassili16-Apr-03 2:11 
GeneralRe: Termination of a thread Pin
David Crow16-Apr-03 2:16
David Crow16-Apr-03 2:16 
GeneralRe: Termination of a thread Pin
Vassili16-Apr-03 3:27
Vassili16-Apr-03 3:27 
GeneralRe: Termination of a thread Pin
David Crow16-Apr-03 3:33
David Crow16-Apr-03 3:33 
GeneralRe: Termination of a thread Pin
Vassili16-Apr-03 4:24
Vassili16-Apr-03 4:24 

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.