#include <stdio.h> #include <windows.h> // for all the Win32 specific thread information
DWORD WINAPI MyThread(LPVOID); // Standard function prototype for Win32 thread
void main(void) { DWORD iID[1]; // array of thread id's HANDLE hThreads[1]; // array of thread handles DWORD waiter; // flag which is set when all therads finish
// create two threads which do the exact same thing hThreads[0] = CreateThread(NULL,0,MyThread,"T1",NULL,&iID[0]);
// wait until threads have finished before parent thread exits waiter = WaitForMultipleObjects(2,hThreads,TRUE,INFINITE); }
DWORD WINAPI MyThread(LPVOID n) // defines what our threads actually do { char* name = (char*)n; // needed to convert passed parameter to a string for (int i=0;i<100; i++) printf("Thread %s: i=%d\n",name,i); return 0; }
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.