Guest User

Untitled

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1.  
  2. DWORD _stdcall TestThread (LPVOID param){
  3.    
  4.     ThreadParams *t = (ThreadParams*) param;
  5.     cout << "thread created!: " << t->threadNum << endl;
  6.     return 0;
  7.    
  8. }
  9.  
  10. CC cc;
  11.     HANDLE thread[5000];
  12.     ThreadParams t[5000];
  13.     for (int i = 0; i < ThreadNum; i++){
  14.         t[i].cc = &cc;
  15.         t[i].threadNum = i;
  16.         if ((thread[i] = CreateThread(NULL, 8192, TestThread, &t[i], 0, NULL)) == NULL ){
  17.             printf("Failed to create thread %d, error %d\n", i, GetLastError());
  18.             exit(-1);
  19.         }
  20.     }
  21.     for (int i = 0; i < ThreadNum; i++) {
  22.         WaitForSingleObject(thread[i], INFINITE);
  23.         CloseHandle(thread[i]);
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment