Jump to content
  • Advertisement

Archived

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

31337noob

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

This topic is 5323 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

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
Advertisement
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
Suit yourself,

There may come a time when priority settings are needed, and you would be a noob not to learn how to do so.


- [BDS]StackOverflow

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!