Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #include<pthread.h>
  4.  
  5. #include<stdlib.h>
  6. #include<unistd.h>
  7.  
  8. void * threadFunc1(void * arg){
  9.  
  10. int i;
  11. int *x=(int *)arg;
  12.  
  13. for(i=1;i<=100;i++){
  14.  
  15. printf("%d\n",x);
  16.  
  17. sleep(1);
  18.  
  19. }
  20.  
  21. }
  22.  
  23. void * threadFunc2(void * arg){
  24.  
  25. int i;
  26. int *y=(int*)arg;
  27.  
  28. if(y==0){
  29. for(i=0;i<=100;i=i+2){
  30. printf("%d\n",i);
  31. sleep(1);
  32. }
  33. }
  34.  
  35. else{
  36. for(i=1;i<=100;i++){
  37. printf("%d\n",2*i-1);
  38. sleep(1);
  39. }
  40. }
  41.  
  42. }
  43.  
  44. int main(void){
  45.  
  46. pthread_t thread1;
  47.  
  48. pthread_t thread2;
  49.  
  50. int x,y;
  51.  
  52. scanf("%d",&x);
  53. scanf("%d",&y);
  54.  
  55. pthread_create(&thread1,NULL,threadFunc1,(void*)x);
  56.  
  57. pthread_create(&thread2,NULL,threadFunc2,(void*)y);
  58.  
  59. while(1);
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement