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

Started by
16 comments, last by 31337noob 20 years, 1 month ago
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 1LONGLONG 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]
[/quote]
Advertisement
Oh my gosh.

That is all I have to say.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Good for you
[/quote]
" "
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]
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
[/quote]
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]
Why?

This topic is closed to new replies.

Advertisement