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 <stdio.h>
#include <pthread.h>
#if defined (Win32)
# include <windows.h>
# define psleep(sec) Sleep ((sec) * 1000)
#elif defined (Linux)
# include <unistd.h>
# define psleep(sec) sleep ((sec))
#endif
static void * funct(void * data);
void main()
{
int ret = 0;
unsigned long id1 = 1;
unsigned long id2 = 2;
unsigned long id3 = 3;
unsigned long id4 = 4;
unsigned long debut1 = 0;
unsigned long debut2 = 1250001;
unsigned long debut3 = 2500001;
unsigned long debut4 = 3750001;
ret = pthread_create (&id1, NULL, funct, (void *) debut1);
ret = pthread_create (&id2, NULL, funct, (void *) debut2);
ret = pthread_create (&id3, NULL, funct, (void *) debut3);
ret = pthread_create (&id4, NULL, funct, (void *) debut4);
pthread_join (id1, NULL);
pthread_join (id2, NULL);
pthread_join (id3, NULL);
pthread_join (id4, NULL);
}
static void * funct(void * data)
{
unsigned long i;
unsigned long debut = (unsigned long) data;
for (i = debut ; i < debut+1250000 ; i++)
printf("%lu\n", i);
return NULL;
} |
Partager