futextest.pthread.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <pthread.h>
  5. #include <unistd.h>
  6. void * print2(void * arg)
  7. {
  8. printf("This is Function 2 - go to sleep\n");
  9. sleep(5);
  10. printf("Function2 out of sleep\n");
  11. printf("%s",(char *) arg);
  12. return NULL;
  13. }
  14. void * print (void *arg)
  15. {
  16. printf("This is Function 1 - go to sleep\n");
  17. sleep(5);
  18. printf("Function1 out of sleep\n");
  19. printf("%s",(char *) arg);
  20. return NULL;
  21. }
  22. void * TestFunc(void * arg )
  23. {
  24. int * ptr = (int *) arg;
  25. printf("Parent gave %d\n",*ptr);
  26. }
  27. int main(int argc, char ** argv) {
  28. pthread_t threadId1,threadId2,threadId3;
  29. int intvar = 12;
  30. printf("MANISAYS :The Functions are at %p %p %p \n",print,print2,TestFunc);
  31. pthread_create(&threadId1, NULL, print, "Thread1 Executing ...\n");
  32. //sleep(2);
  33. pthread_create(&threadId2, NULL, print2, "Thread2 Executing ...\n");
  34. //sleep(2);
  35. pthread_create(&threadId3, NULL, TestFunc,&intvar);
  36. printf("going to sleep\n");
  37. //sleep(2);
  38. printf("out of sleep\n");
  39. pthread_join(threadId1, NULL);
  40. pthread_join(threadId2, NULL);
  41. pthread_join(threadId3, NULL);
  42. return 0;
  43. }