HelpThreads

Posts 1–6 of 6 · Page 1 of 1
Threads
What is the most efficient way of using threads?
I have a few functions with while(true) loops in them. Currently, I use:

Code:
#include <thread>

...

Addition()
{
    ...
}

...

int main ()
{
    thread ADD = thread(Addition);
    ADD.join();
}
I have seen other ways of doing it, so I want to know the best method.
I don't understand what you mean by the most efficient way to use them?

I only use threads when I need them.

You shouldn't use excess number of threads, Microsoft recommends twice as many as the cores on your processor, which you can find with GetSystemInfo.

A separate thread is usually created for callback routines to not interrupt the main thread but allow the event to be handled, so generally people use a pool of threads that act as a callback for a specific task.

But if you want to have multiple threads, each one doing a separate job, then nothing is stopping you?
Quote Originally Posted by __readgsqword View Post
I don't understand what you mean by the most efficient way to use them?

I only use threads when I need them.

You shouldn't use excess number of threads, Microsoft recommends twice as many as the cores on your processor, which you can find with GetSystemInfo.

A separate thread is usually created for callback routines to not interrupt the main thread but allow the event to be handled, so generally people use a pool of threads that act as a callback for a specific task.

But if you want to have multiple threads, each one doing a separate job, then nothing is stopping you?
See I'm just beginning to use these but I can't find much info on them. They're all performing a different function (like bhop, triggerbot), so I want them to run at once.
Quote Originally Posted by KappaMang View Post
See I'm just beginning to use these but I can't find much info on them. They're all performing a different function (like bhop, triggerbot), so I want them to run at once.
Yes, that's fine. But what you could do is place all your functions in one thread to perform each task one after the other, because the the time it takes to execute the instruction is so minuscule, it appears to be simultaneous. You can have a separate thread to toggle the hacks on and off.

For example.
Code:
ULONG ActiveHacks(LPVOID Context)
{
	for(;;)
	{
		if(BHop)
			PerfromBHop();
		if(TriggerBot)
			PerformTriggerBot();
		
		//...

		Sleep(1);//Experiment with the delay
	}
}
Your second thread can simple loop the keyboard state if you want to toggle hacks with hotkeys, or use a global keyboard hook for toggling. It's up to you. If you have an in game hack menu, you can activate and deactivate through that as well.

But you shouldn't need a separate thread for every hack.
Quote Originally Posted by __readgsqword View Post
But you shouldn't need a separate thread for every hack.
I've tried your code, but now I can't do two at once since I have while loops for GetAsyncKeyState in both bhop and trigger. Are there any work arounds?
I did it with threads:

Code:
DWORD WINAPI loops(LPVOID);
bool bhop = false;

int main(){
HANDLE thread = CreateThread(NULL,NULL,loops,NULL,NULL,NULL);

while(1){
   GetAsyncKeyState(....)
    }
}


DWORD WINAPI loops(LPVOID Dick)
{
while(1){
        if(bhop)
           WriteProcessMemory(....)
    }
}
Maybe it's not the best solution, but it works for me
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us