#include <pthread.h>
#include <stdio.h>
void * operacao( const char * nome_thread) {
int a, b;
printf ( "A thread %s pede que você digite o primeiro número: " , nome_thread
) ; printf ( "A thread %s pede que você digite o segundo número: " , nome_thread
) ; printf ( "A soma é %d." , a
+ b
) ; pthread_exit( NULL) ;
return NULL; // Nunca é executado.
}
int main( ) {
pthread_t thread;
printf ( "Criando uma nova thread\n " ) ; int flag = pthread_create( & thread, NULL, operacao, "auxiliar" ) ;
if ( flag != 0 ) {
printf ( "Erro na criação de uma nova thread\n " ) ; return 1 ;
}
operacao( "principal" ) ;
return 0 ;
}
I2luY2x1ZGUgPHB0aHJlYWQuaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CiAgICAKdm9pZCAqb3BlcmFjYW8oY29uc3QgY2hhciAqbm9tZV90aHJlYWQpIHsKICAgIGludCBhLCBiOwogICAgcHJpbnRmKCJBIHRocmVhZCAlcyBwZWRlIHF1ZSB2b2PDqiBkaWdpdGUgbyBwcmltZWlybyBuw7ptZXJvOiAiLCBub21lX3RocmVhZCk7CiAgICBzY2FuZigiJWQiLCAmYSk7CiAgICBwcmludGYoIkEgdGhyZWFkICVzIHBlZGUgcXVlIHZvY8OqIGRpZ2l0ZSBvIHNlZ3VuZG8gbsO6bWVybzogIiwgbm9tZV90aHJlYWQpOwogICAgc2NhbmYoIiVkIiwgJmIpOwogICAgcHJpbnRmKCJBIHNvbWEgw6kgJWQuIiwgYSArIGIpOwogICAgcHRocmVhZF9leGl0KE5VTEwpOwogICAgcmV0dXJuIE5VTEw7IC8vIE51bmNhIMOpIGV4ZWN1dGFkby4KfQogICAgCmludCBtYWluKCkgewogICAgcHRocmVhZF90IHRocmVhZDsKICAgIHByaW50ZigiQ3JpYW5kbyB1bWEgbm92YSB0aHJlYWRcbiIpOwogICAgaW50IGZsYWcgPSBwdGhyZWFkX2NyZWF0ZSgmdGhyZWFkLCBOVUxMLCBvcGVyYWNhbywgImF1eGlsaWFyIik7CiAgICBpZiAoZmxhZyAhPSAwKSB7CiAgICAgICAgcHJpbnRmKCJFcnJvIG5hIGNyaWHDp8OjbyBkZSB1bWEgbm92YSB0aHJlYWRcbiIpOwogICAgICAgIHJldHVybiAxOwogICAgfQogICAgb3BlcmFjYW8oInByaW5jaXBhbCIpOwogICAgcmV0dXJuIDA7Cn0=