Click here to Skip to main content
15,887,302 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMultithreading in general Pin
csrss2-May-10 9:22
csrss2-May-10 9:22 
AnswerRe: Multithreading in general Pin
CPallini2-May-10 9:39
mveCPallini2-May-10 9:39 
AnswerRe: Multithreading in general Pin
csrss2-May-10 9:56
csrss2-May-10 9:56 
GeneralRe: Multithreading in general Pin
Software_Developer3-May-10 2:46
Software_Developer3-May-10 2:46 
AnswerRe: Multithreading in general Pin
ThatsAlok2-May-10 20:01
ThatsAlok2-May-10 20:01 
AnswerRe: Multithreading in general Pin
Rajesh R Subramanian2-May-10 23:02
professionalRajesh R Subramanian2-May-10 23:02 
AnswerRe: Multithreading in general Pin
Emilio Garavaglia3-May-10 1:23
Emilio Garavaglia3-May-10 1:23 
GeneralRe: And he would be violating the rules of threading. Pin
Software_Developer3-May-10 2:59
Software_Developer3-May-10 2:59 
Never, never access the same data between the threads.

Follow the small set of simple rules of threading.
The rules:
Rule #1: Do not access the same data between the threads.
Rule #2: Do not pass references or pointers to variables between threads.
Rule #3: Use windows messages to interact with the GUI.




#1 Do not access the same data between the threads.
The code passes the dialog's this pointer to the thread, but accessing isn't thread safe.

#2 Do not pass references or pointers to variables.
The code passes a pointer to the local ThreadParam variable.
If OnSomeButton goes out of scope before MyThreadProc tries to access the parameter
things will of course go bad.
Allocate with new and let the thread delete it when finished.

#3 Use windows messages to interact with the GUI.
GeneralRe: And he would be violating the rules of threading. Pin
Emilio Garavaglia25-Jun-10 3:04
Emilio Garavaglia25-Jun-10 3:04 
QuestionHow could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 8:43
m_code2-May-10 8:43 
AnswerRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Richard Andrew x642-May-10 8:53
professionalRichard Andrew x642-May-10 8:53 
AnswerRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Michel Godfroid2-May-10 8:58
Michel Godfroid2-May-10 8:58 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 9:07
m_code2-May-10 9:07 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Michel Godfroid2-May-10 9:22
Michel Godfroid2-May-10 9:22 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 9:57
m_code2-May-10 9:57 
GeneralRe: Sample code, the good way Pin
Software_Developer2-May-10 19:08
Software_Developer2-May-10 19:08 
GeneralRe: Sample code, the good way Pin
Randor 3-May-10 6:22
professional Randor 3-May-10 6:22 
GeneralRe: SendMessage is thread-safe because no interaction between the threads Pin
Software_Developer3-May-10 20:01
Software_Developer3-May-10 20:01 
GeneralRe: SendMessage is thread-safe because no interaction between the threads Pin
Randor 4-May-10 5:55
professional Randor 4-May-10 5:55 
GeneralRe: Link to an example (code) Pin
Software_Developer2-May-10 19:41
Software_Developer2-May-10 19:41 
GeneralRe: Link to an example (code) Pin
m_code4-May-10 7:28
m_code4-May-10 7:28 
QuestionWhat does my Logitech keyboard send when I press its special 'E-Mail' key? Pin
glyfyx2-May-10 7:43
glyfyx2-May-10 7:43 
AnswerRe: What does my Logitech keyboard send when I press its special 'E-Mail' key? Pin
Richard Andrew x642-May-10 8:30
professionalRichard Andrew x642-May-10 8:30 
AnswerRe: What does my Logitech keyboard send when I press its special 'E-Mail' key? Pin
Michel Godfroid2-May-10 9:44
Michel Godfroid2-May-10 9:44 
AnswerRe: What does my Logitech keyboard send when I press its special 'E-Mail' key? Pin
glyfyx2-May-10 18:01
glyfyx2-May-10 18:01 

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.