/*
 * thread1.c
 * 
 * Copyright 2024 osboxes <osboxes@osboxes>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * $ gcc -Wall -o thread1 thread1.c -lpthread
 * 
 * programa de hilos que parece estar bien, pero que a veces funciona
 * y otras veces no funciona
 * que esta pasando???
 */


#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *hijoA(void *);  // hilo que imprime letras mayusculas
void *hijob(void *);  // hilo que imprime letras minusculas

int main(int argc, char **argv)
{
	pthread_t hiloA, hilob;
	int rc = pthread_create(&hiloA,NULL,hijoA,NULL);
	printf("main(): rc=%d creando hiloA\n",rc);
	rc = pthread_create(&hilob,NULL,hijob,NULL);
	printf("main(): rc=%d creando hilob\n",rc);
	return 0;
}


void *hijoA(void *p) {  // hilo que imprime letras mayusculas
	char letra='A';
	while(letra <= 'Z') {
		printf("%c\n",letra);
		letra+=2;
	}
	pthread_exit(NULL);
}

void *hijob(void *p) {  // hilo que imprime letras minusculas
	char letra='b';
	while(letra <= 'z') {
		printf("   %c\n",letra);
		letra+=2;
	}
	pthread_exit(NULL);
}
