Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: threads VC++
Can anybody tell me that how to identify that which is worker thread and which is user thread in coding
Posted 17-Apr-12 4:45am
Comments
CPallini at 17-Apr-12 13:39pm
   
usually you know which is the working thread, because you coded it. What exactly do you need?
SAKryukov at 17-Apr-12 14:40pm
   
I think I have an idea what OP may need. Please see my answer.
--SA
vaibhavj_navdurga at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
UINT ThreadFunc (LPVOID pParam)
{
    :
    :
    return 0;
}
and code starting this thread may like this
CWinThread* pThread = AfxBeginThread (ThreadFunc, &threadInfo);
 
A UI thread class declartion may look like below
class CUIThread : public CWinThread
{
    DECLARE_DYNCREATE (CUIThread)
 
public:
    virtual BOOL InitInstance ();
};
and the code creating the UI thread as below
 
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
  Permalink  
Comments
vaibhavj_navdurga at 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)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100