Article View: borland.public.cppbuilder.nativeapi
Article #2711Re: Getting a thread's state and CPU utilization
From: Bob Gonder
Date: Sun, 14 Jan 2007 13:05
Date: Sun, 14 Jan 2007 13:05
33 lines
2147 bytes
2147 bytes
Dennis Jones wrote: >Does anyone know if there is a way to determine the state of a currently >running thread? > I'd like to be able to find out if a thread is executing, terminated, GetExitCodeThread() or check the signal status of the thread handle. WaitForSingleObject( hThread, 0 ) > or waiting on a synchronization object (such as a critical >section or mutex). Set a flag in your thread data indicatiing this ? >Also, is it possible to get a thread's current CPU utilization? I don't think in one call, but GetThreadTimes() might be used to accumulate statistics over several calls. >example, if my application is using 80-90% of the CPU resources, I'd really >like to be able to determine which threads are very busy, and which ones are >using little or no CPU time. For debugging, and figuring out how to automate it (if this is your goal) you might reduce the priority of one thread at a time, and see how that affects the usage. SetThreadPriority() Since you are wanting to reduce priority, you might also want to use the mis-named SetThreadPriorityBoost() (it actually turns off the boost)
Technical Details
Message-ID:
<999kq2l4vmj0mq60qde1gvpcom1l4arf8a@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45a9e77e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2c2b36b510895e0f X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Getting a thread's state and CPU utilization Date: Sun, 14 Jan 2007 05:05:16 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <999kq2l4vmj0mq60qde1gvpcom1l4arf8a@4ax.com> References: <45a9e77e$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 71.0.33.18 X-Trace: newsgroups.borland.com 1168779900 71.0.33.18 (14 Jan 2007 05:05:00 -0800) Lines: 36 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail