5 Mart 2016 Cumartesi

THREAD HATASI

thread creating code : home da.

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

void* thread_func(void* parameter){
        int i=0;
        for(i=0;i<5;i++){
                printf("%d\n",i);
                sleep(5);
        }
        return 0;
}

int main(int argc,char **argv){
        pthread_t thread_handle;
        int ret = pthread_create(&thread_handle,0,thread_func,0);
        if(ret != 0){
                printf("error creating thread! %d",ret);
                return 1;
        }
        pthread_join(thread_handle,0);
        return 0;
}







Calıstırmak icin :

 gcc -o thread1 thread1.c -lpthread
 ./thread1



output:
0
1
2
3
4

Hiç yorum yok:

Yorum Gönder