1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#define nbre_cycle 5
#define nbre_trame 3
#define PTU 2
void *func_th (void *arg)
{
int sig= (int)arg;
int j=0;
fprintf(stderr,"sync frame number: %d ",sig);
for ( j=0;j<nbre_trame;j++)
{
fprintf(stderr,"la trame %hh est envoyée",ST[sig][j]);
}
}
int main(void)
{
int i,j, s=0;
pthread_t th;
char *ST[nbre_cycle][nbre_trame];
for ( i=0;i<nbre_cycle;i++)
{
for (j=0;j<nbre_trame;j++)
{
ST[i][j]=(char*)malloc(3 * sizeof(char));
sprintf(ST[i][j],"%d.%d",i,j);
}
}
while(1)
{
if(( pthread_create(&th,NULL,func_th,(void*)s)!)=0 )
{
fprintf(stderr,"can't create thread");
exit(EXIT_FAILURE);
}
s++;
if (s==1024)
s=0;
sleep(PTU);
}
} |
Partager