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 50
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *thread_start (void *user)
{
char *p = NULL;
/* p = ma_fonction_qui_retourne_un_char* */
printf ("bonjour\n");
return NULL;
}
int main (void)
{
int ret;
pthread_t *th = calloc (2, sizeof (pthread_t));
if (th != NULL)
{
int i;
ret = EXIT_SUCCESS;
for (i = 0; ret == EXIT_SUCCESS && i < 2; i++)
{
printf ("Thread %d\n", i);
if (pthread_create (&th[i], NULL, thread_start, NULL) == -1)
{
printf ("cannot launch a thread");
ret = EXIT_FAILURE;
}
}
/* waiting threads */
for (i = 0; i < 2; i++)
{
pthread_join (th[i], NULL);
}
}
else
{
printf ("Cannot allocate memory for threads");
ret = EXIT_FAILURE;
}
return ret;
} |