Advertisement
Guest User

Untitled

a guest
May 4th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <pthread.h>
  5.  
  6. struct arg_struct{
  7.     int
  8. }
  9.  
  10.     int inverse(int N, int chisl)
  11.     {
  12.         char buffer[BUF];
  13.         int resbuffer[BUF];
  14.  
  15.         snprintf(buffer, sizeof(buffer), "%d", chisl);
  16.  
  17.         for(int i=0; i< strlen(buffer); i++)
  18.         {
  19.             resbuffer[strlen(buffer)-i-1] = abs(N - chisl%10 - 1);
  20.  
  21.             //printf("OSNOV %d - CIFRA %d - 1 = %d\n",N,chisl%10, N - chisl%10 - 1);
  22.  
  23.             chisl=chisl/10;
  24.         }
  25.         int inversed=0;
  26.         for(int i=0; i<strlen(buffer); i++) inversed=10*inversed+resbuffer[i];
  27.         //printf("%d", inversed);
  28.  
  29.         return inversed;
  30.     }
  31.  
  32. static void wait_thread(void)
  33. {
  34.     time_t start_time = time(NULL);
  35.  
  36.     while (time(NULL) == start_time)
  37.     {
  38.         /* do nothing except chew CPU slices for up to one second. */
  39.     }
  40. }
  41.  
  42. static void *thread_func(void *vptr_args)
  43. {
  44.  
  45.     //int convert(int N,int chisl, int length)
  46.     //{
  47.         int result=0;
  48.         for(int i=0; i<length; i++)
  49.         {
  50.             result += chisl%10 * pow(N, i);
  51.             chisl = chisl / 10;
  52.         }
  53.    //}
  54.     int i;
  55.    
  56.     for (i = 0; i < 20; i++)
  57.     {
  58.         fputs("  b\n", stderr);
  59.         wait_thread();
  60.     }
  61.  
  62.     return NULL;
  63. }
  64.  
  65. static void *thread_func(void *vptr_args)
  66. {
  67.     int i;
  68.  
  69.     for (i = 0; i < 20; i++)
  70.     {
  71.         fputs("  b\n", stderr);
  72.         wait_thread();
  73.     }
  74.  
  75.     return NULL;
  76. }
  77.  
  78. int main(void)
  79. {
  80.     int i;
  81.     pthread_t thread1,thread2;
  82.  
  83.     if (pthread_create(&thread1, NULL, convert, NULL) != 0)
  84.     {
  85.         return EXIT_FAILURE;
  86.     }
  87.    
  88.     if (pthread_create(&thread2, NULL, inverse, NULL) != 0)
  89.     {
  90.         return EXIT_FAILURE;
  91.     }
  92.  
  93.     for (i = 0; i < 20; i++)
  94.     {
  95.         puts("a");
  96.         wait_thread();
  97.     }
  98.  
  99.     if (pthread_join(thread, NULL) != 0)
  100.     {
  101.         return EXIT_FAILURE;
  102.     }
  103.  
  104.     return EXIT_SUCCESS;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement