Advertisement
unstoppable7

Untitled

Feb 5th, 2023
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3.  
  4. // Estructura para pasar argumentos a cada hilo
  5. struct thread_args {
  6.     int thread_id;
  7.     char *start;
  8.     char *end;
  9. };
  10.  
  11. // Función ejecutada por cada hilo
  12. void *try_passwords(void *arguments) {
  13.     struct thread_args *args = (struct thread_args *) arguments;
  14.     int thread_id = args->thread_id;
  15.     char *start = args->start;
  16.     char *end = args->end;
  17.  
  18.     // Aquí puedes incluir el código para intentar adivinar contraseñas en el rango [start, end]
  19.     // ...
  20.  
  21.     pthread_exit(NULL);
  22. }
  23.  
  24. int main(int argc, char *argv[]) {
  25.     // Inicializa los hilos
  26.     pthread_t threads[NUM_THREADS];
  27.     struct thread_args thread_args[NUM_THREADS];
  28.  
  29.     // Crea NUM_THREADS hilos, cada uno con su propio rango de contraseñas a probar
  30.     for (int t = 0; t < NUM_THREADS; t++) {
  31.         thread_args[t].thread_id = t;
  32.         thread_args[t].start = ...;
  33.         thread_args[t].end = ...;
  34.         int rc = pthread_create(&threads[t], NULL, try_passwords, (void *) &thread_args[t]);
  35.         if (rc) {
  36.             printf("Error al crear hilo %d\n", t);
  37.             return 1;
  38.         }
  39.     }
  40.  
  41.     // Espera a que todos los hilos terminen
  42.     for (int t = 0; t < NUM_THREADS; t++) {
  43.         pthread_join(threads[t], NULL);
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement