Archived

This topic is now archived and is closed to further replies.

need help!!!!!!!!!!!!!!!!!!!

This topic is 5022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quote:
Original post by 31337noob
no.
i want to set my priority level to high or realtime


You , sir, are a programmer. Your priority level has, however, nothing to do with programming. I assume you are working on something, and you want to be able to set the priority level of that particular thing.

Problem : we don''t know what that thing is.

Mission : tell us what it is.

Reward : the answer.



Victor Nicollet, INT13 game programmer

Share this post


Link to post
Share on other sites
Too many exclamation marks in the thread title. Too little info about the problem in the thread title. No proper problem description in your posts.
Either you have a lot to learn, or you are simply a troll.

Share this post


Link to post
Share on other sites
Hmm, I dont see what is so hard to answer this question:

Use, SetThreadPriority

Of course this will only affect your thread. Here is an example:

#include <windows.h>
#include <process.h>

#define NUM_THREADS 1
LONGLONG sum;

unsigned __stdcall CalcThread( void *arg ) {
for( long i = 0; i < 100000000; i++ ) {
sum += 2;
}

printf("finished thread: %u\n", (long) arg);
return 0;
}

int main() {
HANDLE hthread[NUM_THREADS]; // handles for the threads.

unsigned ThreadID; // Receives each thread's ID.


hthread[0] = (HANDLE) _beginthreadex( NULL, 0, CalcThread, (void *) GetCurrentThreadId(), CREATE_SUSPENDED, &ThreadID );

if( !SetThreadPriority( hthread[0], THREAD_PRIORITY_HIGHEST ) ) {
printf("Priority Set Error\n");
return 0;
}

Sleep( 5000 );

if( ResumeThread( hthread[0] ) == 0xFFFFFFFF ) {
printf("Resuming Thread Error\n");
return 0;
}

Sleep( 1000 );

if( WaitForMultipleObjects( NUM_THREADS, hthread, TRUE, INFINITE ) == WAIT_FAILED ) {
printf("WaitForMultipleObjects failed\n");
}

printf("sum = %u\n", (long)sum);

return 0;
}


That should be all to it. Let me know if you run into any problems. Also be sure to do this:

Go to the project settings, choose the C++ tab and pick "Code Generation" from the ComboBox. Then, set "Use Runtime Library" to the appropriate multithreaded version, I'd recommend 'Multithreaded DLL'.

Edit: Updated source code. If you need a file called MSVCIRTD.dll, you can find it here.
Just scroll down till you find it. Save it to your Windows\System if you are using Win98 or WinME, or Windows\System32 with Win2000 or higher

Example for _beginthreadex. Check the bottom of that page, the example looks similar to the main code above.


Hope this helps,
- [BDS]StackOverflow

[edited by - BlueDev on March 19, 2004 2:00:05 PM]

Share this post


Link to post
Share on other sites
just as an FYI, you rarely want to muck around with thread priority. the OS typically knows what's going on and the normal priority works fine. you're not going to get much of a performance boost (i'd be surprised if you got any at all) out of changing thread priorities and you're just going to piss your users off. i multi-task with just about everything. then UT2004 is loading maps, i alt-tab and check email. if UT2004 was setting its priority to high or realtime my email would be so slow that i'd go insane.

-me

[edited by - Palidine on March 19, 2004 2:49:26 PM]

Share this post


Link to post
Share on other sites
just to let you know i am not using threads.

i just want to set the priority level of my exe to be realtime or high and not by using the task manager. i want to do it in c++.

just to let you know...........

so how would i do that?

[edited by - 31337noob on March 19, 2004 6:58:07 PM]

Share this post


Link to post
Share on other sites