Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- // Estructura para pasar argumentos a cada hilo
- struct thread_args {
- int thread_id;
- char *start;
- char *end;
- };
- // Función ejecutada por cada hilo
- void *try_passwords(void *arguments) {
- struct thread_args *args = (struct thread_args *) arguments;
- int thread_id = args->thread_id;
- char *start = args->start;
- char *end = args->end;
- // Aquí puedes incluir el código para intentar adivinar contraseñas en el rango [start, end]
- // ...
- pthread_exit(NULL);
- }
- int main(int argc, char *argv[]) {
- // Inicializa los hilos
- pthread_t threads[NUM_THREADS];
- struct thread_args thread_args[NUM_THREADS];
- // Crea NUM_THREADS hilos, cada uno con su propio rango de contraseñas a probar
- for (int t = 0; t < NUM_THREADS; t++) {
- thread_args[t].thread_id = t;
- thread_args[t].start = ...;
- thread_args[t].end = ...;
- int rc = pthread_create(&threads[t], NULL, try_passwords, (void *) &thread_args[t]);
- if (rc) {
- printf("Error al crear hilo %d\n", t);
- return 1;
- }
- }
- // Espera a que todos los hilos terminen
- for (int t = 0; t < NUM_THREADS; t++) {
- pthread_join(threads[t], NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement