Threading In C++, By Otoom
Hello, I will show you how to thread in C++.
First you need to create the thread, so if we place this into our editor...
DWORD WINAPI Threadname (LPVOID lPData) { } int main() { }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
Okay, and that is the basic layout.
Now we have declared the thread, of course change Threadname to whatever you would like to call it.
What we can now do is, call on that thread within the main.
So if we add a little bit of code...
DWORD WINAPI Threadname (LPVOID lpData) { } int main() { HANDLE Threadname = CreateThread(NULL,0, Threadname, NULL,0,0); }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
Okay, so, What have we done here?
What we have now done is call upon the thread we declared. Using a handle.
But after all this, i bet you think what can threads even do.
Okay well. Threads let you run something else while running main.
It is like a background running program but within the same application.
For example.
We can show the lyrics of a song, while making the beeps of it.
I hope you get that.
So... Now.
DWORD WINAPI Beeps (LPVOID lpData) { while(1) { cout<<"\a"; } } int main() { HANDLE Beeps = CreateThread(NULL, 0, Beeps, NULL, 0,0); cout<<"You can hear the beeps...\n"; cout<<"While looking at this text...\n"; }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
Just on a side note, the lpData is not needed.
I just included it as thats the way i learned it.
Otoom