Giving parameters to a thread.

Giving parameters to a thread.

See version :

Pas de dépendances

Download :

#include <windows.h>
#include <stdio.h>

typedef struct 
{
    int compteur;
} threaddata;

unsigned long WINAPI Fonction1(void* params)
{
    threaddata* sub = (threaddata*)params;  // recuperation.
    while(1)
    {
        sub->compteur++;
        printf("%d\t",sub->compteur);
        Sleep(1000);
    }
}

int main()
{
    threaddata d;
    HANDLE H1;
    d.compteur = 0;
    H1 = CreateThread(NULL,0,Fonction1,(void*)&d,0,0);
    getchar();
    TerminateThread(H1,0);
    printf("Dernier parametre du thread : %d\n",d.compteur);
    return 0;
}




Explanations

	No explanations yet.