Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anybody tell me that how to identify that which is worker thread and which is user thread in coding
Posted
Comments
CPallini 17-Apr-12 13:39pm    
usually you know which is the working thread, because you coded it. What exactly do you need?
Sergey Alexandrovich Kryukov 17-Apr-12 14:40pm    
I think I have an idea what OP may need. Please see my answer.
--SA
Vaibhav_J_Jaiswal 18-Apr-12 1:15am    
I have a project in which no. of thread classes are used and my TL tell me that identify which is worker thread and which is user. So that's why I'm asking this.

Threads are not classified into "worker", "user" threads, or the like. Threads are threads. However, if you need to identify what thread is executing some code during run time, you can use the Windows API GetCurrentThread, which gives you a thread handle:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683182%28v=vs.85%29.aspx[^].

Just remember, that a value of a thread handle makes sense only in same the process, where this thread is running. The function takes the handle of the thread of the calling code. For example, you can get thread handles in the very beginning of the thread body function, when you certainly know what thread is running, store those values somewhere and later compare with the handles taken during execution of some function in question.

—SA
 
Share this answer
 
v2
From the code you can identify which is worker thread and which is UI thread.
The UI thread class is always derived from CWinThread. You can check in the code who is inherting the class CWinThread.
The worker thread function may look like below
C++
UINT ThreadFunc (LPVOID pParam)
{
    :
    :
    return 0;
}

and code starting this thread may like this
C++
CWinThread* pThread = AfxBeginThread (ThreadFunc, &threadInfo);


A UI thread class declartion may look like below
C++
class CUIThread : public CWinThread
{
    DECLARE_DYNCREATE (CUIThread)

public:
    virtual BOOL InitInstance ();
};

and the code creating the UI thread as below

C++
CWinThread* pThread = AfxBeginThread (RUNTIME_CLASS (CUIThread));

This just helps you in identfying. May be to proceed further, you should have good understnding on the difference between both. For that you can refer any good tutorial
 
Share this answer
 
Comments
Vaibhav_J_Jaiswal 20-Apr-12 2:13am    
Thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900