Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #define NUM_THREADS 2
  6.  
  7. char *num = "0123456789";
  8. char *alpha = "abcdefghijklmnopqrstuvwxyz";
  9.  
  10. void *PrintSeq(void *inSequence)
  11. {
  12. char *i = (char*)inSequence;
  13. while(1)
  14. {
  15. if (*i == 0) i = (char*)inSequence;
  16. printf("%c", *i);
  17. printf("TEST");
  18. i++;
  19. sleep(1);
  20. }
  21. pthread_exit(NULL);
  22. }
  23.  
  24. int main (int argc, char *argv[])
  25. {
  26. printf("PRINT?");
  27. pthread_t threads[NUM_THREADS];
  28.  
  29. int rc;
  30.  
  31. rc = pthread_create(&threads[0], NULL, PrintSeq, (void*)num);
  32. if (rc){
  33. printf("ERROR: Failed to create threads");
  34. exit(-1);
  35. }
  36.  
  37. rc = pthread_create(&threads[1], NULL, PrintSeq, (void*)alpha);
  38. if (rc){
  39. printf("ERROR: Failed to create threads");
  40. exit(-1);
  41. }
  42.  
  43. pthread_exit(NULL);
  44. }
Add Comment
Please, Sign In to add comment