?
Solved

catching current  thread

Posted on 2003-03-16
6
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 

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

Technology Partners: 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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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