Skip to content

Instantly share code, notes, and snippets.

@RicardoLara
Last active March 7, 2016 17:56
Show Gist options
  • Save RicardoLara/18f22d7bd425dfdf75c6 to your computer and use it in GitHub Desktop.
Save RicardoLara/18f22d7bd425dfdf75c6 to your computer and use it in GitHub Desktop.
Por Alma & Ricardo... JEJE :)
/*
Por Alma & Ricardo :3
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
typedef struct h{
int ID;
char msg[50];
}hilo;
void * todoEsBueno(void * p){
hilo * h = (hilo *)p;
printf("Hilo %d\nMsg: %s\n",h->ID,h->msg);
pthread_exit(0);
}
int main(int argc, char **argv){
int i,n;
printf("Pasando %d parametros\n", argc);
n = atoi(argv[1]);
hilo v[n];
pthread_t hilos[n];
for(i=0; i<n; i++){
char aux[50];
printf("Mete el msg: ");
scanf(" %s",aux);
strcat(v[i].msg,aux);
v[i].ID = i;
if(!pthread_create(&hilos[i],NULL,todoEsBueno,(void *)&v[i])) printf(":D\n");
else{ printf(":(\n"); pthread_exit(0); }
}
for(i=0; i<n; i++)
pthread_join(hilos[i],NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment