From Thundering Dolphin, 3 Weeks ago, written in Text.
This paste is a reply to Re: Untitled from Crimson Peafowl - view diff
Embed
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4. #include <unistd.h>
  5.  
  6. void *printmessagefun(void *msg);
  7. void *fact(int num);
  8. void *cube(int num2);
  9. int main()
  10. {
  11.  
  12.         pthread_t t1,t2;
  13.         char *str1 = "hello from thread 1";
  14.         char *str2 = "hi from thread 2";
  15.         int number1 = 4;
  16.         int number2 = 4;
  17.         pthread_create(&t1,NULL,fact,(int)number1);
  18.         pthread_create(&t2,NULL,cube,(int)number2);
  19.  
  20.         pthread_join(t1,NULL);
  21.         pthread_join(t2,NULL);
  22.  
  23.         return 0;
  24. }
  25.  
  26. void *printmessagefun(void *msg)
  27. {
  28.         char *value;
  29.         value = (char*)msg;
  30.         int i;
  31.         for(i =0;i<5;i++)
  32.         {
  33.         printf("%s,\t%d\n",value,i);
  34.         sleep(2);
  35.         }
  36.         pthread_exit(0);
  37. }
  38.  
  39. void *fact(int num)
  40. {
  41.         int i = num, sum = 1;
  42.         for(i; i>0;i--)
  43.         {
  44.                 sum = sum*i;
  45.         }
  46.         printf("%d",sum);
  47. }
  48. void *cube(int num2)
  49. {
  50.         int sum2 = num2*num2*num2;
  51.         printf("\t%d",sum2);
  52. }

Replies to Re: Re: Untitled rss

Title Name Language When
Re: Re: Re: Untitled Bistre Pheasant text 2 Weeks ago.