Sunday, October 11, 2015

pthread

#include "stdio.h"
#include "stdlib.h"
#include "pthread.h"

void thread_run(int m){

    int i = 0;
    while( i < 100 ){
        printf("I am in thread %d\t %d\n", m, i);
        i++;
    }

}

int main()
{
int i;
pthread_t tid;

    for(i = 0; i < 5; i++){
   pthread_create(&tid, NULL, thread_run, i);
    }

pthread_exit(NULL);
return 0;
}

 gcc -lpthread -o pt examp_1.c

No comments: