#include #include #include #include #include #include "thread.h" /* fibonacci. * * la durée doit être proportionnel à la valeur du résultat. * valgrind doit être content. * jusqu'à quelle valeur cela fonctionne-t-il ? * * support nécessaire: * - thread_create() * - thread_join() avec récupération de la valeur de retour * - retour sans thread_exit() */ static void * fibo(void *_value) { thread_t th, th2; int err; void *res = NULL, *res2 = NULL; unsigned long value = (unsigned long) _value; /* on passe un peu la main aux autres pour eviter de faire uniquement la partie gauche de l'arbre */ thread_yield(); if (value < 3) return (void*) 1; err = thread_create(&th, fibo, (void*)(value-1)); assert(!err); err = thread_create(&th2, fibo, (void*)(value-2)); assert(!err); err = thread_join(th, &res); assert(!err); err = thread_join(th2, &res2); assert(!err); return (void*)((unsigned long) res + (unsigned long) res2); } unsigned long fibo_checker( unsigned long n ) { unsigned long a = 1; unsigned long b = 1; unsigned long c, i; if ( n <= 2 ) { return 1; } for( i=2; i