unistd.h Problem Pls.Help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bangaw
    New Member
    • Oct 2006
    • 3

    unistd.h Problem Pls.Help me

    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;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Of course not, it's a unix header, so is pthread.h.

    I think you want stdlib.h and Windows.h instread but lots of your function calls will need changing too.

    Comment

    • bangaw
      New Member
      • Oct 2006
      • 3

      #3
      Originally posted by Banfa
      Of course not, it's a unix header, so is pthread.h.

      I think you want stdlib.h and Windows.h instead but lots of your function calls will need changing too.

      Thanks!!

      i really am not used in using windows c++
      sorry for the bad grammar
      Pls help me, what functions shud i change and to change them with what??
      Pls. help me pls...

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Well anything that is not standard C will need changing

        As far as I can see the only standard C function you call is

        printf

        Everything else needs changing.

        I suggest you look up

        CreateThread
        mutex
        semaphore

        in whatever you are using for your Windows documentation
        (goto msdn.microsoft. com if all else fails)

        Comment

        Working...