[ create a new paste ] login | about

Link: http://codepad.org/X5tGquPJ    [ raw code | output | fork ]

C, pasted on Dec 21:
    #include  <pthread.h>
    #include  <stdlib.h>
    #include  <unistd.h>
    #include  <stdio.h>
     
    pthread_mutex_t ptmutex1;
     
    // imprime .
    void *thread_function01(void *arg) {
       
     
        pthread_mutex_lock(&ptmutex1); 
     
        for (int i=0; i<5; i++) {
            printf(".");
            fflush(stdout);
            sleep(1);
        }
        pthread_mutex_unlock(&ptmutex1);
     
        return NULL;
    }
    // imprime 0
    void *thread_function02(void *arg) {
       
     
        pthread_mutex_lock(&ptmutex1);
        for (int i=0; i<5; i++) {
     
            printf("o");
            fflush(stdout);
            sleep(1);
     
        }
     
        pthread_mutex_unlock(&ptmutex1);
        return NULL;
    }
     
    // imprime +
    void *thread_function03(void *arg) {
       
        pthread_mutex_lock(&ptmutex1);
       
        for (int i=0; i<5; i++) {
            printf("+");
            fflush(stdout);
            sleep(1);
        }
     
        pthread_mutex_unlock(&ptmutex1);
       
        return NULL;
    }
     
    // imprime x
    int main(void) {
       
        pthread_t mithread001, mithread002, mithread003;
       
        if (pthread_create( &mithread001, NULL, thread_function01, NULL) ) {
            printf("Error creando el hilo.");
            abort();
        }
     
        if (pthread_create( &mithread002, NULL, thread_function02, NULL) ) {
            printf("Error creando el hilo.");
            abort();
        }
     
        if (pthread_create( &mithread003, NULL, thread_function03, NULL) ) {
            printf("Error creando el hilo.");
            abort();
        }
     
       
        pthread_mutex_lock(&ptmutex1);
       
        for (int i=0; i<5; i++) {
            printf("x");
            fflush(stdout);
            sleep(1);
        }
     
        pthread_mutex_unlock(&ptmutex1);
       
       
        if (pthread_join(mithread001, NULL)) {
            printf("Error union hilo 1");
            abort();
        }
     
     
        if (pthread_join(mithread002, NULL)) {
            printf("Error union hilo 2");
            abort();
        }
     
        if (pthread_join(mithread003, NULL)) {
            printf("Error union hilo 3");
            abort();
        }
     
        exit(0);
     
    }


Output:
1
2
3
4
5
6
7
8
In function 'thread_function01':
Line 14: error: 'for' loop initial declaration used outside C99 mode
In function 'thread_function02':
Line 28: error: 'for' loop initial declaration used outside C99 mode
In function 'thread_function03':
Line 45: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 79: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: