i'm currently using c++ on windowsXP,
unistd.h doesnt work for windows
what other substitute for it could i use to replace it
Pls. Help me Pls pls
the code goes as follows
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define TRUE 1
#define FALSE 0
#define CHAIRS 3 //Sillas Disponibles
#define CANT_CUST 5 //Cantidad de Clientes
#define T_CUST 0 //Tiempo de llegada de Clientes
#define T_CORTE 3 //Tiempo de corte de pelo
typedef int semaphore;
//Prototipo de funciones
void *customer (void *);
void *barber (void *);
void up (semaphore *);
void down (semaphore *);
semaphore sem_barber=0, sem_customer=0, sem_mutex=1;
int waiting=0;
//Main function
int main (void) {
pthread_t barb_t,cust_t[CANT_CUST];
int i;
pthread_create( &barb_t,NULL,ba rber,NULL);
for (i=0;i<CANT_CUS T;i++){
sleep(T_CUST);
pthread_create( &cust_t[i],NULL,customer, NULL);
}
pthread_join(ba rb_t,NULL);
return(0);
}
void *customer (void *n) {
printf ("Customer:entr ando hay %d esperando\n",wa iting);
down (&sem_mutex);
if (waiting < CHAIRS) {
waiting++;
up (&sem_customer) ;
up (&sem_mutex);
down (&sem_barber) ;
printf ("Customer:M e estan cortando el pelo.\n");
}
else {
up (&sem_mutex);
printf ("Customer:M e fui no hay lugar.\n");
}
}
void *barber (void *j) {
printf ("Barber:Empiez o a trabajar\n");
while (TRUE) {
down (&sem_customer) ;
down (&sem_mutex);
waiting--;
up (&sem_barber) ;
up (&sem_mutex);
printf ("Barber:Comien zo el corte de pelo de un cliente quedan %d esperand
o.\n",waiting);
sleep (T_CORTE);
printf ("Barber:Termin e de cortar el pelo de un cliente quedan %d esperand
o.\n",waiting);
}
}
void up (semaphore *sem) {
*sem+=1;
}
void down (semaphore *sem) {
while (*sem<=0){};
*sem-=1;
}
unistd.h doesnt work for windows
what other substitute for it could i use to replace it
Pls. Help me Pls pls
the code goes as follows
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define TRUE 1
#define FALSE 0
#define CHAIRS 3 //Sillas Disponibles
#define CANT_CUST 5 //Cantidad de Clientes
#define T_CUST 0 //Tiempo de llegada de Clientes
#define T_CORTE 3 //Tiempo de corte de pelo
typedef int semaphore;
//Prototipo de funciones
void *customer (void *);
void *barber (void *);
void up (semaphore *);
void down (semaphore *);
semaphore sem_barber=0, sem_customer=0, sem_mutex=1;
int waiting=0;
//Main function
int main (void) {
pthread_t barb_t,cust_t[CANT_CUST];
int i;
pthread_create( &barb_t,NULL,ba rber,NULL);
for (i=0;i<CANT_CUS T;i++){
sleep(T_CUST);
pthread_create( &cust_t[i],NULL,customer, NULL);
}
pthread_join(ba rb_t,NULL);
return(0);
}
void *customer (void *n) {
printf ("Customer:entr ando hay %d esperando\n",wa iting);
down (&sem_mutex);
if (waiting < CHAIRS) {
waiting++;
up (&sem_customer) ;
up (&sem_mutex);
down (&sem_barber) ;
printf ("Customer:M e estan cortando el pelo.\n");
}
else {
up (&sem_mutex);
printf ("Customer:M e fui no hay lugar.\n");
}
}
void *barber (void *j) {
printf ("Barber:Empiez o a trabajar\n");
while (TRUE) {
down (&sem_customer) ;
down (&sem_mutex);
waiting--;
up (&sem_barber) ;
up (&sem_mutex);
printf ("Barber:Comien zo el corte de pelo de un cliente quedan %d esperand
o.\n",waiting);
sleep (T_CORTE);
printf ("Barber:Termin e de cortar el pelo de un cliente quedan %d esperand
o.\n",waiting);
}
}
void up (semaphore *sem) {
*sem+=1;
}
void down (semaphore *sem) {
while (*sem<=0){};
*sem-=1;
}
Comment