Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <curses.h>
- #include <stdlib.h>
- #include <unistd.h>
- #define MAXX 80 /* Numero di colonne dello schermo */
- #define MAXY 24 /* Numero di righe dello schermo */
- #define N 10
- #define MAX_NUM_RND 10;
- struct pos {
- int coda_num[N];
- };
- void* print_rnd (void* parameters){
- struct pos* p;
- int i;
- p = (struct pos*) parameters;
- for (i=0;i<N;i++){
- p->coda_num[i]=random()%MAX_NUM_RND;
- mvprintw(i,5,"%d",p->coda_num[i]);
- refresh();
- usleep(1000000);
- }
- return NULL;
- }
- void* print_pow (void* parameters){
- struct pos* p;
- int i;
- p = (struct pos*) parameters;
- for (i=0;i<N;i++){
- while (p->coda_num[i]==0);
- mvprintw(i,10,"%d",(p->coda_num[i]*p->coda_num[i]));
- refresh();
- }
- return NULL;
- }
- int main () {
- pthread_t thread1_id;
- pthread_t thread2_id;
- struct pos thread_args;
- //struct pos* p;
- int i;
- for (i=0;i<N;i++){
- thread_args.coda_num[i]=0;
- }
- initscr();
- noecho();
- curs_set(0);
- pthread_create (&thread1_id, NULL, &print_rnd, &thread_args);
- pthread_create (&thread2_id, NULL, &print_pow, &thread_args);
- pthread_join (thread1_id, NULL);
- pthread_join (thread2_id, NULL);
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement