?
Solved

catching current  thread

Posted on 2003-03-16
6
Medium Priority
?
457 Views
Last Modified: 2013-11-20
what i need is to catch thread in moment when it`s active, when i create thread with:
 thread[2]=AfxBeginThread(working, hWnd, THREAD_PRIORITY_NORMAL); //CWinThread* thread[100];
  thread[2] get decimal value (%d) for example '42815072' but when i call:

CurrentThread=AfxGetThread()->m_nThreadID // volatile unsigned int CurrentThread;
CurrentThread get decimal value (%d) fo example '1554',  but i now that CurrentThread in that moment
is thread[2].

How can i compare current thread with some thread from line thread[100] example
if ( AfxGetThread()->m_nThreadID==thread[2]) {// ......  } can be done in this way or there is another tactic.
Or haw can i get shorter value (1554) in thread[2] so i can compere it with
AfxGetThread()->m_nThreadID

tnx for your time.

Vlad
0
Comment
Question by:rapidlord
6 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 8147114
GetCurrentThreadID() gives you the thread id of the thread you are currently in.

0
 

Author Comment

by:rapidlord
ID: 8147254
GetCurrentThreadID() returning the same value like AfxGetThread()->m_nThreadID so its again same thing i can compare it with 'thread[2]' IT`S NOT THAT.

sory
0
 

Author Comment

by:rapidlord
ID: 8147269
GetCurrentThreadID() returning the same value like AfxGetThread()->m_nThreadID so its again same thing i can compare it with 'thread[2]' IT`S NOT THAT.

sory
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rapidlord
ID: 8147273
GetCurrentThreadID() returning the same value like AfxGetThread()->m_nThreadID so its again same thing i can compare it with 'thread[2]' IT`S NOT THAT.

sory
0
 
LVL 4

Expert Comment

by:AmitAgarwal
ID: 8148064
Hi No its not same
Thread id and thread handle both are different thing you can not compare these two

0
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 8158066
Hi,

you should simply be able to call something like:
if ( AfxGetThread()->m_nThreadID==thread[2]->m_nThreadID)
or
if ( GetCurrentThread()==thread[2]->m_hThread )

but, you should previously ensure that 'thread[2]!= NULL'

or, instead of storing the CWinThread* returned by AfxBeginThread
you could store either the thread ID or the thread handle, i.e.

CWinThread* pThread;
HANDLE threadHandles[100];
UINT threadIDs[100];
if ( NULL != ( pThread = AfxBeginThread(...) ) )
{
 threadHandles[2]=pThread->m_hThread;
 threadIDs[2]=pThread->m_nThreadID;
}

...

if ( GetCurrentThread() == threadHandles[2] )
 ...
// or
if ( GetCurrentThreadID() == threadIDs[2] )
 ...

hope that helps,

ZOPPO
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question