🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12801

Re: How can i rise the priority of one process

#12801
From: Vladimir Afanasyev
Date: Tue, 18 Nov 2003 11:59
38 lines
2253 bytes
Hi Antonio.

"Antonio Farfan" <amfm0777@hotmail.com> wrote:
>Hello everybody:
>
>  i have an application multithread, and i want to use all the resource of
>CPU. I set the priority
>of the threads to Highest Critical, but my doubt is that if this thread is
>scheduled with all process in the system, or it is scheduled  under his
>process. How can i modify the priority of the main thread VCL.
>

If you want to increase priority of your thread up to max you must 
to increase process class priority as well as thread priority.

Two Win32 API function do it - SetPriorityClass for process 
and SetThreadPriority for thread. 
It can be look as follow:

bool res=SetPriorityClass(
    GetCurrentProcess(),	// handle to the process  
    REALTIME_PRIORITY_CLASS // priority class value 
   );
bool res1=SetThreadPriority(
    GetCurrentThread(),	// handle to the thread 
    THREAD_PRIORITY_TIME_CRITICAL  // thread priority level 
   );

Two additional things:
1. It is a really bad idea to make such thing for a long time. 
This way you can stop some very important process in the 
operating system and come in the deadlock.
2. If you work in Windows NT/2000/XP there are only some 
user can increase priority (as a rule it is local Administrator). See Control Panel -> Admin -> Local policy -> 
user rigts.

Vladimir.
Technical Details
Message-ID: <3fba17a4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3fb9f69b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,ba1f8727712e7aa4
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-18 05:09:36 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: How can i rise the priority of one process
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 212.82.216.226     
X-Forwarded-For: 192.168.0.147
References:  <3fb9f69b$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <3fba17a4$1@newsgroups.borland.com>
Date: 18 Nov 2003 04:59:16 -0700
X-Trace: newsgroups.borland.com 1069160356 207.105.83.66 (18 Nov 2003 04:59:16 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail