Advertisement
nigu

thread_pow

Nov 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <curses.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #define MAXX 80 /* Numero di colonne dello schermo */
  6. #define MAXY 24 /* Numero di righe dello schermo */
  7. #define N 10
  8. #define MAX_NUM_RND 10;
  9.  
  10. struct pos {
  11.     int coda_num[N];
  12. };
  13.  
  14.  
  15.  
  16.  
  17. void* print_rnd (void* parameters){
  18.    
  19.     struct pos* p;
  20.     int i;
  21.     p = (struct pos*) parameters;
  22.    
  23.     for (i=0;i<N;i++){
  24.             p->coda_num[i]=random()%MAX_NUM_RND;
  25.             mvprintw(i,5,"%d",p->coda_num[i]);
  26.             refresh();
  27.             usleep(1000000);
  28.     }
  29.    
  30.    
  31.          
  32.     return NULL;   
  33. }
  34.  
  35. void* print_pow (void* parameters){
  36.    
  37.     struct pos* p;
  38.     int i;
  39.     p = (struct pos*) parameters;
  40.    
  41.     for (i=0;i<N;i++){
  42.             while (p->coda_num[i]==0);
  43.             mvprintw(i,10,"%d",(p->coda_num[i]*p->coda_num[i]));
  44.             refresh();
  45.     }
  46.    
  47.    
  48.          
  49.     return NULL;   
  50. }
  51.  
  52.  
  53.  
  54. int main () {
  55.         pthread_t thread1_id;
  56.         pthread_t thread2_id;
  57.         struct pos thread_args;
  58.         //struct pos* p;
  59.         int i;
  60.         for (i=0;i<N;i++){
  61.             thread_args.coda_num[i]=0;
  62.         }
  63.        
  64.        
  65.         initscr();
  66.         noecho();
  67.         curs_set(0);
  68.        
  69.         pthread_create (&thread1_id, NULL, &print_rnd, &thread_args);
  70.         pthread_create (&thread2_id, NULL, &print_pow, &thread_args);
  71.         pthread_join (thread1_id, NULL);
  72.         pthread_join (thread2_id, NULL);
  73.        
  74.         endwin();
  75.         return 0;
  76.        
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement