Avatar
🏃
1 results for Developpement
  • Un petit exemple vaut mieux que de grands discours, voici le source en C :

    #include 
    #include 
    #include 
    #include <sys/time.h>
    #include <sys/types.h>
    #include 
    static long debut = 0;
    void* longue_pause(void* a){
            pid_t t = getpid();
            printf("pid = %d\n",(int)t);
            printf("thread longue_pause %d debut : %ld\n",(int)pthread_self(),time(0)-debut);
            sleep(10);
            printf("thread longue_pause %d fin : %ld\n",(int)pthread_self(),time(0)-debut);
    }
    void* petites_pauses(void* a){
    	int i = 0;
            pid_t t = getpid();
            printf("pid = %d\n",t);
            printf("thread petites_pauses %d debut : %ld \n",(int)pthread_self(), time(0)-debut);
            for(; i < 10 ;++i){
                    printf("thread petites_pauses %d en cours : %ld \n",(int)pthread_self(), time(0)-debut);
                    sleep(1);
            }
    }
    int main(){
            pthread_t longue;
            pthread_t petit1;
            pthread_t petit2;
            debut = time(0);
            pthread_create(&longue,NULL,longue_pause,NULL);
            pthread_create(&petit1,NULL,petites_pauses,NULL);
            pthread_create(&petit2,NULL,petites_pauses,NULL);
    	sleep(8);
    	printf("Debut join: %ld\n",time(0)-debut);
            pthread_join(longue,NULL);
            printf("fin long : %ld\n",time(0)-debut); 
            pthread_join(petit1,NULL);
    	printf("fin petit1 : %ld\n",time(0)-debut);	
            pthread_join(petit2,NULL);
    	printf("fin petit2 : %ld\n",time(0)-debut);
    }

    Pour la compilation :

    c developpement Created Wed, 17 Oct 2018 00:00:00 +0000