Advertisement
kofii12345

pthreads1

Mar 23rd, 2013
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <pthread.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. using namespace std;
  9.  
  10. void *myFunction(void* arg)
  11. {
  12.     char *s = (char*)arg;
  13.     for(int i = 0; i<10; i++){
  14.         cout<<i<<"\t"<<s<<"\n";
  15.     }
  16.     return NULL;
  17. }
  18.  
  19. int main()
  20. {
  21.  
  22.     pthread_t thread1, thread2;
  23.     int res1, res2;
  24.  
  25.     char* string1 = "THREAD 1";
  26.     char* string2 = "THREAD 2";
  27.    
  28.     res1 = pthread_create(&thread1, NULL, myFunction, string1);
  29.     pthread_join(thread1, NULL);
  30.     res2 = pthread_create(&thread2, NULL, myFunction, string2);
  31.     system("pause");
  32.  
  33. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement