Advertisement
redshadow

Hello World pthread

Jan 19th, 2011
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4.  
  5. #include <pthread.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. void *print( void* );
  10.  
  11. int main( int argc, char *argv[] )
  12. {
  13.         pthread_t threads[2];
  14.         int rc;
  15.         char* hello = "hello ";
  16.         char* world = "world\n";
  17.  
  18.         rc = pthread_create( &threads[0], NULL, print, (void*)hello );
  19.         if( rc ) exit( -1 );
  20.         rc = pthread_create( &threads[1], NULL, print, (void*)world );
  21.         if( rc ) exit( -1 );
  22.  
  23.         pthread_exit( NULL );
  24.  
  25. }
  26.  
  27. void *print( void* word )
  28. {
  29.         char* w;
  30.         w = (char*)word;
  31.         printf( "%s", w );
  32.  
  33.         pthread_exit(NULL);
  34. }
  35.  
  36. #ifdef __cplusplus
  37. }
  38. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement