Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <pthread.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. struct Data{
  10.     string a;
  11.     string b;
  12. };
  13.  
  14.  
  15. void* thread_func( void *param ){
  16.  
  17.  
  18.     struct Data *input = (struct Data*)param;
  19.  
  20.     string data1 = input->a;
  21.     string data2 = input->b;
  22.  
  23.  
  24.     cout << "You said: " << data1 << " " << data2 << endl;
  25.  
  26.     return NULL;
  27. }
  28.  
  29. int main( int argc, char *argv[] )
  30. {
  31.     pthread_t child;
  32.     string arg, arg2;
  33.  
  34.     struct Data *input;
  35.  
  36.     cout << "Input 1: " << endl;
  37.     cin >> arg;
  38.     cout << "Input 2: " << endl;
  39.     cin >> arg2;
  40.  
  41.     input->a = arg;
  42.     input->b = arg2;
  43.  
  44.  
  45.  
  46.     pthread_create( &child, NULL, thread_func, (void *)&input);
  47.  
  48.     pthread_join( child, NULL );
  49.     cout << "Synced" << endl;
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement