Click here to Skip to main content
13,050,904 members (63,980 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Can anybody tell me that how to identify that which is worker thread and which is user thread in coding
Posted 17-Apr-12 3:45am
CPallini 17-Apr-12 13:39pm
usually you know which is the working thread, because you coded it. What exactly do you need?
SAKryukov 17-Apr-12 14:40pm
I think I have an idea what OP may need. Please see my answer.
vaibhavj_navdurga 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
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:[^].

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.

Rate this: bad
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
    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
vaibhavj_navdurga 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2017
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