Http://blog.csdn.net/chen825919148/article/details/7904305
# Include <windows. h >#include <iostream >#include <string> using namespace std; dword winapi myThread (LPVOID argv); // declare a thread function int main (int argc, char * argv []) {string s; HANDLE myHandle = NULL; do {cin. clear (); cin. sync (); cin> s; switch (s. at (0) {case '0': myHandle = CreateThread (NULL, 0, myThread, (LPVOID) s. c_str (), 0, NULL); // create a thread break; case '1': if (myHandle) SuspendThread (myHandle); // suspend a thread break; c Ase '2': if (myHandle) ResumeThread (myHandle); // restore the thread break; case '3': if (myHandle) TerminateThread (myHandle, 0 ); // terminate the thread break; case '4': if (myHandle) SetThreadPriority (myHandle, THREAD_PRIORITY_NORMAL); // set the thread priority break; default: break ;} cout <s <endl;} while (s! = "Exit" & s! = "Quit"); return 0;} dword winapi myThread (LPVOID argv) {int I = 0; char buff [200]; ZeroMemory (buff, sizeof (buff )); memcpy (buff, argv, 200); while (++ I) {cout <"Extra thread executing with argument string:" <buff <endl; Sleep (1000 ); if (I = 40) ExitThread (0); // exit the thread }}
Output result: