Avatar de usuario por pello in January 1, 1970, 1:00 am
Un ejemplo simple de pthread. Un hilo debe ir asociado a una funcion. Una funcion c se puede pasar como un parametro mas.
/**
* hilos.c
* Pello Xabier Altadill Izura
*  un ejemplo simplon de hilos linux
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <pthread.h>

void haz_algo(int *);
void haz_algo_simple(int *);

int h1 = 0, h2 = 0;

extern int
main(void)
{
  pthread_t thread1, thread2;

printf("vamos a ver...
"); 

// creamos el primer
  if (pthread_create(&thread1, NULL, (void *) haz_algo, (void *) &h1) != 0)
	perror("pthread_create"), exit(1); 

// creamos el segundo hilo
  if (pthread_create(&thread2, NULL,(void *) haz_algo_simple, (void *) &h2) != 0)
	perror("pthread_create"), exit(1); 

// esperamos que acabe  
  if (pthread_join(thread1, NULL) != 0)
	perror("pthread_join"),exit(1);

printf("
OK!a
"); 

  return 0; 
}

// funcion haz_algo
void haz_algo(int *veces)
{
  int i;
  
  for (i = 0;  i < veces; i++) 
    printf("Aqui, haciendo algo: %d
",i); 

}

//funcion haz_algo_simple
void haz_algo_simple(int *veces)
{
  int i;
  
  for (i = 0;  i < veces; i++) 
    printf("Aqui, haciendo algo simple: %d
",i); 

}

7 comments |  PELMAlink |  2350 reads
0 de 0
dejar comentario
Comentarios
#1 avatar de hUtMjrUok dice:
www.insur-policies.com/ whole life insurance ilj www.washingtonstatebusinessinsurance.com/ business insurance =-OO www.insurpartners.net/ home insurance 8P
+-0 de 0
in May 15, 2011, 6:47 pm
#2 avatar de viagra dice:
viagra asdasdas viagra jkhkjh viagra 1232 viagra 1232 viagra 1232 cialis 1232 cialis 1232 1232 generic viagra 1232423423 cialis 1232 buy cialis dgdg buy cialis 56465 buy cialis 56465 viagra online asdjaksdn buy viagra asdj cheap viagra asdjaksdn buy viagra online asdjaksdn cheap viagra asdjaksdn buy cialis 64654 viagra online without prescription
viagra asdasdas viagra online fsde cheap viagra fsde buy viagra fsde viagra 665445 viagra 1232 viagra 1232 viagra online without prescription 553434 viagra online without prescription 65456 buy cialis 9876 cialis 1232 cialis 1232 cialis 1232 viagra 1232 generic viagra 1232 buy cialis gdfgdfg cialis 5345 cialis 543543 phentermine without prescription 66544 phentermine without prescription 7766 cialis 5345 cialis 543543 cheap viagra fsde viagra online without prescription asdasdas viagra
+-0 de 0
in August 21, 2011, 4:43 pm
#3 avatar de cheap cialis dice:
sjmapz cialisaga.com/ cheap cialis 0308 cheapcialistab.com/ cialis online 8578 buycialistab.com/ cialis sKunU cheapviagratab.com/ viagra online qANmF buyviagratab.net/ viagra >:-OOO viagraaga.com/ viagra cDRajr
+-0 de 0
in January 28, 2012, 2:11 am
+-0 de 0
in February 9, 2012, 6:23 pm
#5 avatar de viagra alternatives dice:
ofhhixfu viagrapillsforsale.net/ viagra alternatives :-O cialispillsforsale.com/ cialis prices :-O cialispillsforsale.net/ cialis hoVYFq rxviagraforsale.net/ buy viagra TuiWxM
+-0 de 0
in February 22, 2012, 7:29 pm
#6 avatar de bad credit Payday loans dice:
iriaxyq fastcashpaydayloans4u.com/ bad credit Payday loans :-O paydayloanscash4u.co.uk/ Payday Loans UK 9492 simplefastpaydayloans.com/ fast Payday loan CGoXsJ paydayloanscash4u.com/ Payday Loans KjTAo paydayloanslowrates.ca/ Payday Loans %-[[[ servicepaydayloans.ca/ payday loans Canada 1677
+-0 de 0
in March 5, 2012, 11:42 am
+-0 de 0
in March 20, 2012, 10:00 am
Show all fields