12.07.2015 Views

Hilos - Universidad Nacional de San Antonio Abad del Cusco

Hilos - Universidad Nacional de San Antonio Abad del Cusco

Hilos - Universidad Nacional de San Antonio Abad del Cusco

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

UNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCOSISTEMAS DE OPERACIONES IGUIA DE LABORATORIOecp 3 <strong>de</strong> 8COMPILAR UN PROGRAMA QUE UTILIZA HILOS.Para compilar un programa que utiliza hilos, <strong>de</strong>beos utilizar el modificador –lpthread <strong>de</strong>l gcc.Así para compilar el programa llamado ejemplo.c que utiliza hilos, la or<strong>de</strong>n <strong>de</strong> compilación<strong>de</strong>berá ser:gcc –o ejemplo ejemplo.c –pthread4) TRABAJO DE LABORATORIO.a) Escriba una aplicación que cree un hilo que imprima un carácter por consolaSolución/**/Nombre : creaHilo.cObjetivo : crea un hilo que imprime el carácter XAutor : Edwin CarrascoFCreacion : 06/12/2007FModificacion :#inclu<strong>de</strong>#inclu<strong>de</strong>void imprime_x(void ){while(1){fputc('X',st<strong>de</strong>rr);}pthread_exit(0);}main(){// Variablespthread_t hilo;int iret;// creamos un hilo que ejecuta el proceso imprime_xiret = pthread_create(&hilo, NULL,(void*) imprime_x, NULL);// Este proceso imprime el caracter '0'while(1){fputc('O',st<strong>de</strong>rr);}}exit(0);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!