Exemple #1
0
/*-----------------------------------------------------------------*/
int main(int argc, char* argv[]) {
   long i; 
   int key, success, attempts;
   pthread_t* thread_handles;
   int inserts_in_main;
   unsigned seed = 1;
   double start, finish;

   if (argc != 2) Usage(argv[0]);
   thread_count = strtol(argv[1],NULL,10);

   Get_input(&inserts_in_main);

   /* Try to insert inserts_in_main keys, but give up after */
   /* 2*inserts_in_main attempts.                           */
   i = attempts = 0;
   while ( i < inserts_in_main && attempts < 2*inserts_in_main ) {
      key = my_rand(&seed) % MAX_KEY;
      success = Insert(key);
      attempts++;
      if (success) i++;
   }
   printf("Inserted %ld keys in empty list\n", i);

#  ifdef OUTPUT
   printf("Before starting threads, list = \n");
   Print();
   printf("\n");
#  endif

   thread_handles = malloc(thread_count*sizeof(pthread_t));
   pthread_mutex_init(&mutex, NULL);
   pthread_mutex_init(&count_mutex, NULL);

   GET_TIME(start);
   for (i = 0; i < thread_count; i++)
      pthread_create(&thread_handles[i], NULL, Thread_work, (void*) i);

   for (i = 0; i < thread_count; i++)
      pthread_join(thread_handles[i], NULL);
   GET_TIME(finish);
   printf("Elapsed time = %e seconds\n", finish - start);
   printf("Total ops = %d\n", total_ops);
   printf("member ops = %d\n", member_total);
   printf("insert ops = %d\n", insert_total);
   printf("delete ops = %d\n", delete_total);

#  ifdef OUTPUT
   printf("After threads terminate, list = \n");
   Print();
   printf("\n");
#  endif

   Free_list();
   pthread_mutex_destroy(&mutex);
   pthread_mutex_destroy(&count_mutex);
   free(thread_handles);

   return 0;
}  /* main */
Exemple #2
0
void Wait_end_of_click(void)
{
  // On désactive tous les raccourcis clavier

  while(Mouse_K)
    Get_input(20);
}
int main(int argc, char* argv[])
{
long i; 
int key, success, attempts;
pthread_t* thread_handles;
int inserts_in_main;
unsigned seed = 1;
double inicio, fin;

if (argc != 2) Usage(argv[0]);
thread_count = strtol(argv[1], NULL, 10);
Get_input(&inserts_in_main);

i = attempts = 0;
pthread_mutex_init(&head_mutex, NULL);
while ( i < inserts_in_main && attempts < 2*inserts_in_main )
{
   key = my_rand(&seed) % MAX_KEY;
   success = Insert(key);
   attempts++;
   if (success) i++;
}
printf("%ld keys insertadas\n", i);

#  ifdef OUTPUT
   printf("Antes de crear hilos, lista = \n");
   Print();
   printf("\n");
#  endif

thread_handles = malloc(thread_count*sizeof(pthread_t));
pthread_mutex_init(&count_mutex, NULL);

GET_TIME(inicio);
for (i = 0; i < thread_count; i++)
   pthread_create(&thread_handles[i], NULL, Thread_work, (void*) i);

for (i = 0; i < thread_count; i++)
   pthread_join(thread_handles[i], NULL);
GET_TIME(fin);
printf("Tiempo de ejecución = %e segundos\n", fin - inicio);
printf("Total operaciones = %d\n", total_ops);
printf("Operaciones miembro = %d\n", total_miembro);
printf("Operaciones insertar = %d\n", total_insertar);
printf("Operaciones borrado = %d\n", total_borrado);

#  ifdef OUTPUT
   printf("Despues de terminar los hilos, lista = \n");
   Print();
   printf("\n");
#  endif

Free_list();
pthread_mutex_destroy(&head_mutex);
pthread_mutex_destroy(&count_mutex);
free(thread_handles);

return 0;
}
Exemple #4
0
void Redefine_control(word *shortcut, int x_pos, int y_pos)
{
  Hide_cursor();
  Print_in_window(x_pos,y_pos,"*PRESS KEY OR BUTTON*",MC_Black,MC_Light);
  Display_cursor();
  while (1)
  {
    Get_input(20);
    if (Key==KEY_ESC)
      return;
    if (Key!=0)
    {
      *shortcut=Key;
      return;
    }
  }    
}
Exemple #5
0
int main(int argc, char** argv) {
   double n, h, total_int;
   double start, finish, elapsed;

   Get_input(argc, argv, &n); /*Read user input */

   h = (b-a)/n;          /* length of each trapezoid */

   start = clock();
   /* Calculate integral using endpoints*/
   total_int = Trap(a, b, n, h);
   finish = clock();
   elapsed = (double)(finish-start)/CLOCKS_PER_SEC;
 
   printf("With n = %.0f trapezoids, our estimate\n", n);
   printf("of the integral from %.0f to %.0f = %.0f\n", a, b, total_int);
   printf("Elapsed time = %f milliseconds \n", elapsed * 1000);

   return 0;
} /*  main  */