Question : Interview Question: Threads

hi,
how do you differentiate between the ui thread and worker thread?
how does two threads communicate in a process?
does all threads have message handling capability?
how does the ui thread communicate with worker thread and vice versa?

Answer : Interview Question: Threads

UI thread use the events that are created with CreateEvent API. These events (their handles) are known for the UI thread and the worker thread. UI thread raises the events by calling SetEvent. The working thread is always in a waiting mode - it contains a loop with WaitForMultipleObject inside - this function allows to wait for few events and if one these events gets the signaled state, this thread can perform an action.
If the working thread need to notify the UI thread, it sends a message to the main window of this thread.
 
Random Solutions  
 
programming4us programming4us